UITextView自适应高度解决方法

if (content) {
        CGSize constraint = CGSizeMake(self.contentWide, CGFLOAT_MAX);
        CGSize size = [content sizeWithFont:contentFont constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
        
        frame = CGRectMake(self.contentX, y, self.contentWide, size.height+16);
        UITextView *textView = [[UITextView alloc] initWithFrame:frame];
        
        textView.text = content;
      
        
        textView.autoresizesSubviews = YES;
        textView.autoresizingMask =(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
        
        textView.backgroundColor = [UIColor clearColor];
        textView.userInteractionEnabled = NO;
    
        
        textView.textColor = contentColor;
        [contentView addSubview:textView];
        [textView release];
        
        y += (textView.contentSize.height);
    }
    
//    UITextView *textView = [[UITextView alloc] initWithFrame:frame];
//   
//    if (content) {
//        
//        textView.backgroundColor = [UIColor clearColor];
//        textView.userInteractionEnabled = NO;
//        textView.text = content;
//        [textView setFrame:CGRectMake(self.contentX, y, self.contentWide, textView.contentSize.height)];
//        CGFloat height = textView.contentSize.height;
//        [textView setFrame:CGRectMake(self.contentX, y, self.contentWide, height)];
//        textView.textColor = contentColor;
//        [contentView addSubview:textView];
//        [textView release];
//         y += (textView.frame.size.height + 16);
//
//    }

你可能感兴趣的:(UITextView)