ios - Possible to get UIButton sizeThatFits to work? -


i have been using method of resizing uibuttons depreciated, , not robust. , other reasons, want sizethatfits work uibuttons. i've read online, i'm not sure if should work (seems working some, not others, difference maybe between style, i'm using custom).

here simple test code recreate issue (i put in viewdidload test, shouldn't matter, , real code part of large project):

uibutton *btn = [uibutton buttonwithtype:uibuttontypecustom]; [btn settitle:@"this test long title need word wrap more single line when displayed on tiny ipod in portrait view." forstate:uicontrolstatenormal]; btn.titlelabel.linebreakmode = uilinebreakmodewordwrap; // depreciated - nothing replace it? cgrect r = btn.frame; r.origin.x = 0; r.origin.y = 0; r.size.width = 320; r.size.height = [btn.titlelabel.text sizewithfont:btn.titlelabel.font constrainedtosize:cgsizemake(r.size.width,100000) linebreakmode:btn.titlelabel.linebreakmode].height; // returns approx 86 , changes correctly if change title text r.size.height = [btn sizethatfits:cgsizemake(r.size.width,cgfloat_max)].height; // returns 34 no matter btn.frame = r; 

the sizewithfont line have been doing, , works, isn't asking actual control size, not safe , has been depreciated also. sizethatfits line working, returns 34 no matter (probably recommended/default height of button).

i've been using same sizewithfont resize uilabels , other controls well. i've updated them use sizethatfits , work great, uibutton isn't working same others. i'm hoping there simple fix, setting property of uibutton, working?

my app needs support ios 8+, not older versions.

update: based on comments here how resize uibutton fit text without going wider screen? , accepted answer, seems might stuck sizewithfont or other sub-par solutions... dang.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -