开发者

How to get the lenth of each line of the text when wordwrap is considered

开发者 https://www.devze.com 2022-12-27 23:15 出处:网络
I meet a problem as follows: I have a NSString displayed in a UILabel into multiple lines with WordWrap mode = UILineBreakModeWordWrap, rendered into 2 lines

I meet a problem as follows: I have a NSString displayed in a UILabel into multiple lines with WordWrap mode = UILineBreakModeWordWrap, rendered into 2 lines NSStr开发者_C百科ing* myText = @"I am here Work".

"I am here_" //Line 1. _ is for blank. "Work" //Line 2.

Is there anyway for me to get the width for the substring 'I am here'? and also for 2nd line 'Work'

If that's hard, How can I know which part of the whole string is in line 1? and which part is in line 2?

thanks in advance.


Look up the UIKit additions to NSString:

(CGSize)sizeWithFont:(UIFont *)font 
//Returns the size of the string if it were to be rendered with the specified font on a single line.

(CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size 
// Returns the size of the string if it were rendered and constrained to the specified size.

(CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode
//Returns the size of the string if it were rendered with the specified constraints.
0

精彩评论

暂无评论...
验证码 换一张
取 消