1. 程式人生 > >textview 自適應高度

textview 自適應高度

-(void)textViewDidChange:(UITextView *)textView{
	
	if (textView.frame.size.height>100) {//當textview的高度到100時,返回
		return;
	}
	
<p class="p1"><span class="s1"><span>	</span>CGfloat height = [textView </span><span class="s2">sizeThatFits</span><span class="s1">:</span><span class="s2">CGSizeMake</span><span class="s1">(textView.</span><span class="s3">frame</span><span class="s1">.</span><span class="s3">size</span><span class="s1">.</span><span class="s3">width</span><span class="s1">, </span><span class="s4">FLT_MAX</span><span class="s1">)].</span><span class="s3">height</span><span class="s1">;</span></p>	//設定高度
	textView.frame = CGRectMake(20, 30, 100, height);
}