如何动态UITextView高度包含增量以及子视图动态与textview高度和移动按钮在ios中

时间:2015-12-22 07:25:50

标签: ios7

enter image description here

我正在使用此代码,但文本视图从子视图外部

CGRect frame = self.dealDetailTextView.frame;
frame.size.height = self.dealDetailTextView.contentSize.height;
self.dealDetailTextView.frame = frame;

CGRect moreViewFrame =  self.popUpView.frame;
moreViewFrame.size.height = frame.size.height + 150;
self.popUpView.frame = moreViewFrame;

1 个答案:

答案 0 :(得分:0)

- (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);

    //Set new frame size and also change popUpView frame base on newFrame
    textView.frame = newFrame;

}