iOS-UILabel的宽度自适应文字
2015-12-14 17:26
204 查看
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];//这个frame是初设的,没关系,后面还会重新设置其size。
[label setNumberOfLines:0];
NSString *s = @"这个frame是初设的,没关系,后面还会重新设置其size.";
UIFont *font = [UIFont fontWithName:@"Arial" size:12];
CGSize size = CGSizeMake(320,2000);
CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakModeWordWrap];
[label setFrame:CGRectMake(0,0, labelsize.width, labelsize.height)];
[self.view addSubView:label];
[label setNumberOfLines:0];
NSString *s = @"这个frame是初设的,没关系,后面还会重新设置其size.";
UIFont *font = [UIFont fontWithName:@"Arial" size:12];
CGSize size = CGSizeMake(320,2000);
CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakModeWordWrap];
[label setFrame:CGRectMake(0,0, labelsize.width, labelsize.height)];
[self.view addSubView:label];
相关文章推荐
- ZnDuiDesigner 版本更新
- 蓝牙BR/EDR和Bluetooth Smart的十大重要区别
- Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]
- UICollectionView的简单使用(一)
- Leetcode194: Range Sum Query 2D - Immutable
- openstack devstack tox ValueError: need more than 1 value to unpack
- iOS开发备忘录:自定义UINavigationBar背景图片和Back按钮
- uilabel的字体不一致
- LeetCode 300 Longest Increasing Subsequence
- django queryset values&values_list
- easyui dialog 引入jsp页面赋值
- Leetcode193: Range Sum Query - Immutable
- Android Stuido 导出 APK
- [ERROR] The goal you specified requires a project to execute but there is no POM in this directory
- Storm 提交拓扑后UI中spout、bolt的Num都显示为0
- rpmbuild线上实战
- 为嵌套在左右滑动的UIScrollview上的UITableView增加滑动删除
- iOS 十六进制的颜色值转换为UIColor
- iOS UITableView分割线颜色,长度自定义
- vs2010出现如下错误: VCEnd" exited with code 1.