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);
//
//    }

posted @ 2012-12-21 14:07  人魔七七  阅读(7950)  评论(0编辑  收藏  举报