我正在尝试根据它将显示的文本量设置 UITextView 的高度。我在这里找到了这个解决方案:
CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.frame = frame;
但我无法让它工作,我认为这与我没有正确使用 addSubview 将 UITextView 添加到视图有关,但我无法弄清楚!我相信这是一个很容易解决的问题。
这是我的 viewcontroller.m 文件代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize textView = _textView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.view addSubview: _textView];
CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.frame = frame;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end