label中文字的自适应
2016-05-30 15:13
507 查看
我们在做App的过程中有时UI设计的一些界面上的文字只给出了其距离左右的间距,以及文字的大小,并没有给出文字的长和宽,这时我们需要利用Label的自适应。其实利用label的自适应更多的情况是label上的文字并并不确定,如用户名,这时更需要我们利用label的自适应。
代码如下:
UILabel * attentionLbl = [[UILabel
alloc] init];
attentionLbl.backgroundColor = [UIColor
redColor];
attentionLbl.font = [UIFont
systemFontOfSize:17];
attentionLbl.textColor = [UIColor
colorWithRed:255 /
255.0
green:255 /
255.0
blue:255 /
255.0
alpha:1];
attentionLbl.text =
@"关住";
CGFloat attentionX =
0;
CGFloat attentionY =
20;
NSMutableDictionary * attentionDic = [NSMutableDictionary
dictionary];
attentionDic[NSFontAttributeName] = [UIFont
systemFontOfSize:17];
CGSize attentionSize = [attentionLbl.text
sizeWithAttributes:attentionDic];
attentionLbl.frame = (CGRect){{attentionX, attentionY},attentionSize};
[self.view
addSubview:attentionLbl];
代码如下:
UILabel * attentionLbl = [[UILabel
alloc] init];
attentionLbl.backgroundColor = [UIColor
redColor];
attentionLbl.font = [UIFont
systemFontOfSize:17];
attentionLbl.textColor = [UIColor
colorWithRed:255 /
255.0
green:255 /
255.0
blue:255 /
255.0
alpha:1];
attentionLbl.text =
@"关住";
CGFloat attentionX =
0;
CGFloat attentionY =
20;
NSMutableDictionary * attentionDic = [NSMutableDictionary
dictionary];
attentionDic[NSFontAttributeName] = [UIFont
systemFontOfSize:17];
CGSize attentionSize = [attentionLbl.text
sizeWithAttributes:attentionDic];
attentionLbl.frame = (CGRect){{attentionX, attentionY},attentionSize};
[self.view
addSubview:attentionLbl];
相关文章推荐
- javaweb文件上传路径在windows和linux上的兼容性问题
- phpstorm 设置自动换行
- 性能测试loadrunner好教程
- react with JSX for {if…else…}
- 19-ffmpeg-commands-for-all-needs
- Android直接使用JDBC+SSH连接外网MySQL数据库
- netstat命令
- android实现图片旋转
- 【原创分享·微信支付】 C# MVC 微信支付教程系列之公众号支付
- Javascript基础知识二:JQuery
- Android网络框架:OKHttp源码简单解析(一)
- Spring技术内幕之Spring Data JPA-自定义Repository实现
- JNDI(二) 之 Overview of JNDI
- PL/SQL Developer使用技巧、快捷键
- leetcode 241. Different Ways to Add Parentheses-分治算法
- Android Studio Gradle打包实践之多渠道+版本号管理
- OSS设置CORS规则以后还是报No 'Access-Control-Allow-Origin'解决方法
- Google Guava之--cache
- Linux的时间同步到时间服务器
- iOS NSError