多行自动,调整大小的UITextView(Multiple lines automatically-

2019-10-17 11:31发布

我想插入一对夫妇串到我UITextView所以垂直显示

尝试这种代码:

NSMutableString* examinationsString = [NSMutableString string];

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

return examinationsString;

我已经改变UITextView Lines属性到5,但仍然让所有在同一行,用“/”分隔

我究竟做错了什么?

我还希望UITextView拉伸,如果有超过10行,如果它当然不是自动实现的

Answer 1:

请尝试以下代码:

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;


Answer 2:

尝试这个:

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


文章来源: Multiple lines automatically-resizeable UITextView