简体   繁体   English

多行自动调整大小的UITextView

[英]Multiple lines automatically-resizeable UITextView

I want to insert a couple of strings to my UITextView so they are displayed vertically 我想在我的UITextView插入几个字符串,以便它们垂直显示

Tried this code: 试过这段代码:

NSMutableString* examinationsString = [NSMutableString string];

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

return examinationsString;

I had changed UITextView Lines property to 5 but still getting all in one line, separated with "/" 我已经将UITextView Lines属性更改为5,但仍然将所有内容都改为一行,用“/”分隔

What am I doing wrong? 我究竟做错了什么?

I'd also want the UITextView to stretch if there are more than 1 line, if it's not achieved automatically of course 我还希望UITextView在有超过1行时拉伸,如果它当然没有自动实现的话

Please try following code: 请尝试以下代码:

NSMutableString* examinationsString = [NSMutableString string];

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

Now to resize the UITextView as per the view's contentSize : 现在根据视图的contentSize调整UITextView大小:

CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM