textView 自动换行, 可以文本内容动态移动

-(void)textViewDidChange:(UITextView *)textView{
   
//博客园-FlyElephant
   
static CGFloat maxHeight = 95;
   
CGRect frame = textView.frame;
   
   
   
CGSize constraintSize = CGSizeMake(frame.size.width, MAXFLOAT);
   
CGSize size = [textView sizeThatFits:constraintSize];
   
if (size.height<=maxHeight) {
        size.
height=maxHeight;
    }
    textView.
scrollEnabled = NO;    // 不允许滚动
    textView.
frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, size.height);
}

你可能感兴趣的:(iOS开发)