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 uilabels 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 uilabels in appropriate place in uiscrollview name resulttypescrollview. resulttypeimagewidth constant i've defined , set 100 give space between uilabels.

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,

  1. as i'm using custom font, suspect using custom font problem. so, changed 1 of system font, has no effect.
  2. i tried set nslinebreakmodeto nslinebreakbyclipping prevent text getting truncated. after that, text doesn't truncated but, characters missing got truncated before.
  3. 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

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -