Label或Button自适应宽高或文字大小
2016-12-29 11:52
435 查看
1、确定Label或Button的字体大小,使其宽高自适应
UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 30)]; contentLabel.font = [UIFont systemFontOfSize:15];//-------->定义Font的大小 contentLabel.backgroundColor = [UIColor redColor]; contentLabel.text = @"我已知晓,且已阅读并同意以上条款"; [contentLabel sizeToFit];//-------->注意和上面一句代码顺序不能颠倒 [self.View addSubview:contentLabel];
2、确定Label或Button的宽度,使字体大小自适应
//无需自己设置字体大小 UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 30)]; contentLabel.backgroundColor = [UIColor redColor]; contentLabel.text = @"我已知晓,且已阅读并同意以上条款"; contentLabel.adjustsFontSizeToFitWidth = YES;//默认为NO-------->注意和上面一句代码顺序不能颠倒 [self.View addSubview:contentLabel];
如果是Button的话,和上面一样,只有一点小小的区别:
[button.titleLabel sizeToFit]; button.titleLabel.adjustsFontSizeToFitWidth = YES;
相关文章推荐
- UIlabel文字大小自适应label宽度变大变小
- Label自适应文字大小
- button根据文字内容大小自适应
- swift3.0计算label,button的文字大小 rect size
- iOS7 Label自适应文字内容大小
- ios开发系列之label自适应大小
- iOS label根据显示内容自适应大小
- UITextView根据文字大小自适应高度
- iOS AutoLayout自动布局中级开发教程label等文字自动适应大小,宽度
- iOS UILabel 自适应文字的大小
- iOS-UIButton-文字位置,字体大小,边角样式,button种类,点击事件,内容位置
- iOS 开发~设置label上文字显示不同大小、颜色、字体类型
- UILabel文字大小自适应之--SizeToFit
- JavaScript自适应调整文字大小
- TextView文字大小自适应
- 设置行间距,自适应文字大小
- iosiOSlabel基本使用以及文字自适应
- Uilabel自适应文字的大小
- iOS for循环创建button,button的宽度根据上面的文字来自适应.(自适应宽度且自动换)
- QT画图教程1:实现给label上面显示图并且让图自适应控件大小