iphone - Height when using sizeWithFont:constrainedToSize:lineBreakMode with NSLineBreakByTruncatingTail -
when run next code (ios 6.1 sdk):
uifont *font = [uifont fontwithname:@"avenir" size:12.0]; nsstring *text1 = @"short label"; nsstring *text2 = @"long label text truncated because long view"; cgsize text1size = [text1 sizewithfont:font constrainedtosize: cgsizemake(self.view.frame.size.width, cgfloat_max) linebreakmode:nslinebreakbytruncatingtail]; cgsize text2size = [text2 sizewithfont:font constrainedtosize: cgsizemake(self.view.frame.size.width, cgfloat_max) linebreakmode:nslinebreakbytruncatingtail]; nslog(@"text 1 size: %f %f", text1size.width, text1size.height); nslog(@"text 2 size: %f %f", text2size.width, text2size.height); the log output is:
text 1 size: 62.000000 17.000000 text 2 size: 300.000000 34.000000 why heights different, here? in either case, it's 1 line of text; 1 truncated, other not.
thanks!
the height different because gave cgfloat_max height, method tries figure out size text breaking text multiple lines. in case, apparently, 2 lines plenty contain string in width supplied.
iphone ios objective-c ipad nsstring
No comments:
Post a Comment