简体   繁体   中英

Multiple lines automatically-resizeable UITextView

I want to insert a couple of strings to my UITextView so they are displayed vertically

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 "/"

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

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 :

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

尝试这个:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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