UITextView自适应内容高度

设置属性

self.contentTV.delegate = self;
//这一句很重要
self.contentTV.scrollEnabled = NO;
//禁止三方键盘换行
self.contentTV.ignoreSwitchingByNextPrevious = YES;

实现代理

#pragma mark - UITextViewDelegate
-(void)textViewDidChange:(UITextView *)textView{
    //这一句很关键
    [textView sizeToFit];
    CGFloat height = textView.contentSize.height;
    if(height > 84){
        self.heightLC.constant = height;
    }else{
        self.heightLC.constant = 84;
    }
}

你可能感兴趣的:(UITextView自适应内容高度)