1. UIFont *font = [UIFont systemFontOfSize:12];  
    2. CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(150.0f, 1000.0f) lineBreakMode:UILineBreakModeCharacterWrap];
    3. 获取字符串在指定的size内(宽度超过150,则换行)所需的的实际高度和宽度.
    4. 将获取的宽度和高度用于UILabel
    5. UILabel *bubbleText = [[UILabel alloc] initWithFrame:CGRectMake(21.0f, 14.0f, size.width+10, size.height+10)];  
    6. bubbleText.backgroundColor = [UIColor clearColor];  
    7. bubbleText.font = font;  
    8. bubbleText.numberOfLines = 0;  
    9. bubbleText.lineBreakMode = UILineBreakModeCharacterWrap;  
    10.   
    11. bubbleText.text = text;
posted on 2012-04-24 23:05  chivas  阅读(797)  评论(0编辑  收藏  举报