【发布时间】:2011-11-17 18:11:31
【问题描述】:
我在单个页面上有 n 个 UITextView,UITextView 的高度和宽度分别为 200*300(因不同的文本视图而异)。我需要限制最大值。用户可以在每个 textview 中输入的文本行数/字符数,具体取决于 TextView 的 ht 和宽度。我有需要在文本视图中输入的字符的字体大小。那么我该如何实施呢?
【问题讨论】:
标签: iphone objective-c ios ipad uitextview
我在单个页面上有 n 个 UITextView,UITextView 的高度和宽度分别为 200*300(因不同的文本视图而异)。我需要限制最大值。用户可以在每个 textview 中输入的文本行数/字符数,具体取决于 TextView 的 ht 和宽度。我有需要在文本视图中输入的字符的字体大小。那么我该如何实施呢?
【问题讨论】:
标签: iphone objective-c ios ipad uitextview
textfield number of lines:
If you are using iOS 3, you need to use the leading property:
int numLines = txtview.contentSize.height / txtview.font.leading;
If you are using iOS 4, you need to use the lineHeight property:
int numLines = txtview.contentSize.height / txtview.font.lineHeight;
【讨论】:
你可以做的是,你可以计算文本的高度,你可能会限制文本视图的高度和宽度。 现在您可以比较文本高度和文本视图高度。并按照您的要求做任何事情。
计算文字高度:-
CGSize labelsize;
NSString *text=@"your text";
[textView setFont:[UIFont fontWithName:@"Helvetica"size:14]];
labelsize=[text sizeWithFont:textView.font constrainedToSize:CGSizeMake(280, 2000.0) lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"%f",labelsize.height);
if(labelsize.height>300)
{
//show text with 300 height
}
else
{
//show full text
}
【讨论】: