ios - UIButton auto-adjust Button font size Swift -


i try make out quiz , have problem answer buttons. simple fact: text long , try auto-adjust cells using different methods. current status:

        btn in btnarr{         btn.titlelabel!.minimumscalefactor = 0.3         btn.titlelabel!.numberoflines = 0         btn.titlelabel!.adjustsfontsizetofitwidth = true         btn.titlelabel?.baselineadjustment = uibaselineadjustment.aligncenters         //btn.contentedgeinsets = uiedgeinsets(top: 3.0,left: 3.0,bottom: 3.0,right: 3.0)     } 

i hope has option me make work :)

regards, patrick

edit:

 self.view.addconstraint(nslayoutconstraint(item: btn.titlelabel!, attribute: nslayoutattribute.height, relatedby: nslayoutrelation.equal, toitem: btn, attribute:nslayoutattribute.height, multiplier: 0.99, constant: 0))   

with auto layout can set space between buttons, , max , min size. in code labels use:

self.button.titlelabel.numberoflines = 0; self.button.titlelabel.adjustsfontsizetofitwidth = yes; 

with labels adjust text size.

for adjust button titlelabel use auto layout constraint titlelabel. examples:

  [self.view addconstraint:[nslayoutconstraint constraintwithitem:self.button.titlelabel                                                           attribute:nslayoutattributeheight                                                           relatedby:nslayoutrelationequal                                                              toitem:self.view                                                           attribute:nslayoutattributeheight                                                          multiplier:0.5                                                            constant:0]]; 

this constraint define height of titlelabel 50% of self.view height. can adapte constraint need.

this work in code?


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -