iphone - Finding the correct width of a NSString -
on factors wrapping of text inside textview depends. width of textview 160 px , calculated width of incoming text using below mentioned code , comes out 157 px text wrapped in 3 lines... why so?
cgsize size = [mytext sizewithfont:textviewfont constrainedtosize:textview.frame.size linebreakmode:uilinebreakmodewordwrap]; cgfloat textwidth = size.width;
i thought of dividing width of text width of textview number of lines. calculation returns me 1 whereas can see 3 lines coming in textview on simulator.
- (cgsize)sizewithfont:(uifont *)font constrainedtosize:(cgsize)size linebreakmode:(uilinebreakmode)linebreakmode
calculates size string if drawn constrained size given argument, if string long given size constraint truncated fit.
to width of string if it's drawn on single line no constraints use:
- (cgsize)sizewithfont:(uifont *)font
note: of ios7
- (cgsize)sizewithfont:(uifont *)font
is deprecated, instead use:
- (cgsize)sizewithattributes:(nsdictionary *)attrs
Comments
Post a Comment