您的位置:首页 > 大数据 > 人工智能

sizeWithFont:constrainedToSize:lineBreakMode的使用 (2012-03-20 10:48:40)转载▼ 标签: 宽度 字符串 获取 指定 用于 杂谈 分类:

2013-10-15 11:38 826 查看


sizeWithFont:constrainedToSize:lineBreakMode的使用

 (2012-03-20 10:48:40)


转载▼

标签: 


宽度

 


字符串

 


获取

 


指定

 


用于

 


杂谈

分类: IPhone
UIFont *font = [UIFont systemFontOfSize:12];  

CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(150.0f, 1000.0f) lineBreakMode:UILineBreakModeCharacterWrap];

获取字符串在指定的size内(宽度超过150,则换行)所需的的实际高度和宽度.

将获取的宽度和高度用于UILabel

UILabel *bubbleText = [[UILabel alloc] initWithFrame:CGRectMake(21.0f, 14.0f, size.width+10, size.height+10)];  

bubbleText.backgroundColor = [UIColor clearColor];  

bubbleText.font = font;  

bubbleText.numberOfLines = 0;  

bubbleText.lineBreakMode = UILineBreakModeCharacterWrap;  

  

bubbleText.text = text;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios
相关文章推荐