2010-04-26 20 views
1

我遇到了一個如下問題: 我有一個NSString顯示在UILabel中,多行顯示爲WordWrap mode = UILineBreakModeWordWrap,呈現爲2行 NSString * myText = @「我在這裏工作」。如何在考慮wordwrap時得到文本每一行的長度

「我here_」 // 1號線_是空白。 「工作」 //線路2

反正是有,我得到的字符串「我在這裏」的寬度是多少?也爲2號線「工作」

如果這很難,我怎麼能知道這整個字符串的一部分,是在1號線?哪一部分在第2行?

在此先感謝。

回答

3

中查找的UIKit補充的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. 
相關問題