UILabel圆角、边框、宽度自适应
2015-09-01 16:10
477 查看
//设置圆角_userCompanyLabel.layer.masksToBounds = YES;//必须设置_userCompanyLabel.layer.cornerRadius = labelHight/2;//设置圆角的弧度,等于label的高的一半的时候,是个圆
//设置边框_userCompanyLabel.layer.borderColor = [SNColorFromRGB(backgroundColor1) CGColor];//边框颜色_userCompanyLabel.layer.borderWidth = 4;//边框的宽度宽度自适应
_userCompanyLabel.text = text;CGFloat width = 78;
//根据text来找到宽度,size为最大宽度和最大高度,当为单行时options为<span style="font-family: Arial, Helvetica, sans-serif;">NSStringDrawingUsesLineFragmentOrigin即可,为多行时</span><span style="font-family: Arial, Helvetica, sans-serif;">NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading,attributes中设置front,</span><span style="font-family: Arial, Helvetica, sans-serif;"></span> CGRect rect = [text boundingRectWithSize:CGSizeMake(320, 40) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:28]} context:nil];if (rect.size.width > 78) {width = rect.size.width;}[_userCompanyLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(_userNameLabel.mas_bottom).offset(6*bili);make.centerX.equalTo(_userNameLabel.mas_centerX);make.size.mas_equalTo(CGSizeMake(width, 28));}];
相关文章推荐
- QuickServer自学笔记(一)
- *** Assertion failure in -[CompensaCommentView _dequeueReusableViewOfType:withIdentifier:],
- 详解 CALayer 和 UIView 的区别和联系
- 使用pytest+requests进行接口测试实践——测试post请求
- MySQL高速缓存启动方法及参数详解query_cache_size=32M query_cache_type=1
- MySQL高速缓存启动方法及参数详解query_cache_size=32M query_cache_type=1
- MySQL高速缓存启动方法及参数详解query_cache_size=32M query_cache_type=1
- 利用Runtime修改UIdatePicker的字体颜色
- Android学习笔记之DocumentBuilder的使用....
- [Bluetooth(SDK)]使用WinSock连接到远程设备
- 使用pytest+requests进行接口测试实践——测试get请求
- #inception# Follow Your Heart and Persue Your Dream
- uva live 5031 Graph and Queries(Treap x 并查集)
- Myslq 启动报错The server quit without updating PID file
- 【iOS知识学习】_iPhone学习多个UITextField 键盘弹起
- [Bluetooth API]使用Irprops库搜索蓝牙设备
- iOS开发 UIScrollView自带的缩放功能(简单的例子)
- div设置contentEditable="true"作为文本编辑器,定位光标解决办法
- UITouch
- Git+gerrit user guide