2 回答

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
- (void)textViewDidChange:(UITextView *)textView{ CGFloat fixedWidth = textView.frame.size.width; CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)]; CGRect newFrame = textView.frame; newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height); textView.frame = newFrame;}
let fixedWidth = textView.frame.size.width let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))textView.frame. size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
textview.scrollEnabled = NO;

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超4個(gè)贊
這不再適用于iOS 7或更高版本。
UITextView
UITextView
contentSize
.
CGRect frame = _textView.frame;frame.size.height = _textView.contentSize.height;_textView.frame = frame;
contentSize
UITextView
addSubview
frame.size
sizeThatFits
constant
CGSize sizeThatShouldFitTheContent = [_textView sizeThatFits:_textView.frame.size]; heightConstraint.constant = sizeThatShouldFitTheContent.height;
heightConstraint
[self.textView sizeToFit];
CGRect _f = self.mainPostText.frame;_f.size.height = self.mainPostText.contentSize.height;self.mainPostText.frame = _f;
- 2 回答
- 0 關(guān)注
- 851 瀏覽