UITextView使用 sizeWithFont:constrainedToSize:lineBreakMode:计算自适应文本高度

-(CGSize)dynamicHeightForTextViewWithFont:(UIFont*)s_font ConstrainSize:(CGSize)s_size{
    //UItextView 会有一个padding,为8
    
//详情:http://www.1mima.com/uitextview使用-sizewithfontconstrainedtosizelinebreakmode计算高度不准确的解决方案/
    
//维护 bmleung@weiwo.com
    CGSize adapter_size = CGSizeMake(s_size.width - 16, s_size.height); // 宽度减去padding,8*2 = 16
    CGSize txtContentSize = [self sizeWithFont:s_font constrainedToSize:adapter_size lineBreakMode:UILineBreakModeWordWrap ];
    
    txtContentSize.height += 16//高度增加8*2 =  16
    
    
    return txtContentSize;

}

 

 

 

/link http://www.1mima.com/uitextview使用-sizewithfontconstrainedtosizelinebreakmode计算高度不准确的解决方案/
posted @ 2012-10-17 21:40  snowlueng  阅读(557)  评论(0编辑  收藏  举报