2013-07-11 92 views
0

我已完成调整UITextView的大小以适应其内容使用以下代码片段(source)。可调整大小的UITextView以适应其内容

UITextView* textView = [[UITextView alloc]initWithFrame:CGRectMake(0.0f,0.0f,300.0f,10.0f)]; 
[self.view addSubview:textView]; 

textView.text = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"; 

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

我的问题是,我不想以编程方式创建UITextView。当我从Interface Builder添加它并通过@property引用它时,上面的代码不起作用。 frame返回null。我已经把里面viewDidLoad这个代码,所以我认为这是因为在UITextView的初始化或添加到视图控制器,但(?)

有另一种方式来做到这一点,而无需创建UITextView编程?

回答

0

,如果你有在Interface Builder迷上了财产你不这样做

UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(0.0f,0.0f,300.0f,10.0f)]; 
[self.view addSubview:textView]; 

。删除这些线,并在IB中设置它,它应该工作正常。

+0

嗨感谢您的回复。是的,我确实评论了这些线,并仔细检查了连接。虽然没有用 – Isuru

相关问题