我想根據它將顯示的文本的數量來設置UITextView的高度。我發現這個解決這個放在這裏:無法從其內容設置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
感謝您的快速回復,讓它立即與此工作! – user2255616 2013-04-07 22:28:55
不客氣。如果答案對您有幫助,請考慮提升和/或接受它。 – 2013-04-07 22:29:33
我已經接受,但不能upvote它,直到我有15名聲望:( – user2255616 2013-04-07 22:39:23