ios7 UILabel sizeWithFont方法的最新写法
ios7以后 摒弃了 sizeWithFont方法,那么该怎么改写呢
不换行
CGSize fontSize = [string sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15}];
换行的话,首先要设置 UILabel 的 numberOfLines属性等于0,然后再计算Size
NSAttributedString *name = [[NSAttributedString alloc]initWithString:string attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]}]; CGRect nameRect = [name boundingRectWithSize:CGSizeMake("你想要的宽度", CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin context:nil]; CGSize nameSize = nameRect .size;
ios7 UILabel sizeWithFont方法的最新写法
最新推荐文章于 2018-03-03 12:49:21 发布
本文介绍了iOS7之后UILabel尺寸计算的新方法。对于不换行的情况,使用sizeWithAttributes方法进行计算;若需换行,则先将UILabel的numberOfLines设为0,再利用NSAttributedString结合CGSizeMake方法来获取所需尺寸。
2053

被折叠的 条评论
为什么被折叠?



