ios - NSString sizeWithFont forWidth returning wrong values -


i have weird problem. sizewithfont: forwidth: linebreakmode:nslinebreakbywordwrapping returning wrong values. have array of strings need placed in neat "table". cells uiviews uilabels in them. in order alloc-init cell view , label right frame need pre-compute desired height of cell , total height of wrapper view since cells placed in view. code looks this:

#define kstandardfontofsize(x)  [uifont fontwithname:@"helveticaneue-ultralight" size:x]  cgfloat size = 0.0f; //for computing total size cells placed in view items = [nsarray arraywithobjects:@"you have 23 new followers", @"1125 new likes", @"successful week 24 new twitter followers , 60 new email subscribers", @"1125 new tickets", nil];  (nsstring *item in items) {     if ([item sizewithfont:kstandardfontofsize(16) forwidth:100 linebreakmode:nslinebreakbywordwrapping].height < 25)         size += 70; //either cell 70 (140) pixels tall or 105 (210)pixels     else         size += 105;     nslog(@"%f, %f, %@", [item sizewithfont:kstandardfontofsize(16) forwidth:100 linebreakmode:nslinebreakbywordwrapping].width, [item sizewithfont:kstandardfontofsize(16) forwidth:100 linebreakmode:nslinebreakbywordwrapping].height, item); } 

but log returning weird values:

82.000000, 20.000000, have 23 new followers 99.000000, 20.000000, 1125 new likes 70.000000, 20.000000, successful week 24 new twitter followers , 60 new email subscribers 67.000000, 20.000000, 1125 new tickets 

how possible width of "1125 new likes" 99 , long string 70? height should greater 20 or?

try use [[nsstring string] sizewithfont:uifont constrainedtosize:cgsize linebreakmode:(nslinebreakmode)]


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -