iphone - adjustsFontSizeToFitWidth doesn't properly work -
i'm developing app ios > 5.0 , using xcode 4.6.2 explain problem, i've uiscrollview
contains bunch of uilabel
. text i'm going display in these uilabel
s dynamic but, uilabel
's frame constant, if current text doesn't fit in frame width, need scale font size down. so, i've found adjustsfontsizetofitwidth
property of uilabel
.
here explanation took directly uilabel
class reference.
a boolean value indicating whether font size should reduced in order fit title string label’s bounding rectangle.
yeap, thought that's looking since text i'm going display in uilabel
1 line. so i'm aware of property should used numberoflines
property set 1.
here code make happen.
for (nsstring *currentimage in self.imagesnames) { uilabel *lbl = [[uilabel alloc]initwithframe:cgrectmake(imagenumber*resulttypeimagewidth, 10, 75, 35)]; [lbl setfont:[uifont fontwithname:@"gothamrounded-bold" size:25]]; [lbl setnumberoflines:1]; [lbl settext:currentimage]; [lbl setbackgroundcolor:[uicolor clearcolor]]; [lbl settextcolor:[uicolor colorwithhue:0.07 saturation:1 brightness:0.49 alpha:1.0]]; [lbl adjustsfontsizetofitwidth]; [lbl settextalignment:nstextalignmentcenter]; imagenumber++; [self.resulttypescrollview addsubview:lbl]; }
imagenumber
int i'm using place uilabel
s in appropriate place in uiscrollview
name resulttypescrollview
. resulttypeimagewidth
constant i've defined , set 100 give space between uilabel
s.
so, problem if text doesn't fit in label's frame, gets truncated. expected if text doesn't fit frame, font size scale down fit it. @ least, that's understand uilabel
class reference. apparently, i'm missing something, ?
so far,
- as i'm using custom font, suspect using custom font problem. so, changed 1 of system font, has no effect.
- i tried set
nslinebreakmode
tonslinebreakbyclipping
prevent text getting truncated. after that, text doesn't truncated but, characters missing got truncated before. - i've used
minimumscalefactor
set different values see if has effect, but, no effects @ all.
this should work without changing many defaults. posted code doesn't set adjustsfontsizetofitwidth
, gets it. setting this:
lbl.adjustsfontsizetofitwidth = yes;
Comments
Post a Comment