多行自动调整大小的UITextView

时间:2012-12-03 10:11:38

标签: ios uitextview

我想在我的UITextView插入几个字符串,以便它们垂直显示

试过这段代码:

NSMutableString* examinationsString = [NSMutableString string];

for (NSString * examination in examinationsArray)
{
    [examinationsString appendString:[NSString stringWithFormat:@"%@, %s ",examination, "\n"]];
}

return examinationsString;

我已将UITextView Lines属性更改为5但仍然将所有内容更改为一行,用" /"

分隔

我做错了什么?

如果有超过1行,我还希望UITextView延长,如果它当然没有自动实现

2 个答案:

答案 0 :(得分:2)

请尝试以下代码:

NSMutableString* examinationsString = [NSMutableString string];

for (NSString * examination in examinationsArray)
{
    [examinationsString appendString:[NSString stringWithFormat:@"%@,\n",examination]];
}
return examinationsString;

现在根据视图的UITextView

调整contentSize的大小
CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

答案 1 :(得分:1)

试试这个:

[examinationsString appendString:[NSString stringWithFormat:@"%@,\n",examination]];