多行可自动调整大小的 UITextView [英] Multiple lines automatically-resizeable UITextView

查看:29
本文介绍了多行可自动调整大小的 UITextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

试过这个代码:

NSMutableString* examinationsString = [NSMutableString string];

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

return examinationsString;

我已将 UITextView Lines 属性更改为 5,但仍将所有内容放在一行中,并以/"分隔

I had changed UITextView Lines property to 5 but still getting all in one line, separated with "/"

我做错了什么?

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

I'd also want the UITextView to stretch if there are more than 1 line, if it's not achieved automatically of course

推荐答案

请尝试以下代码:

NSMutableString* examinationsString = [NSMutableString string];

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

现在根据视图的 contentSize 调整 UITextView 的大小:

Now to resize the UITextView as per the view's contentSize:

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

这篇关于多行可自动调整大小的 UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆