//获取字符串的宽度
+(float) widthForString:(NSString *)string fontSize:(float)fontSize{
NSDictionary *attrs = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:17]};
CGSize size=[string sizeWithAttributes:attrs];
return size.width;
}
//获得字符串的高
+(float) heightForString:(NSString *)string fontSize:(float)fontSize{
NSDictionary *attrs = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:17]};
CGSize size=[string sizeWithAttributes:attrs];
return size.height;
}
iOS 根据文字的多少计算label宽度
NSDictionary *attrs = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:17]}; CGSize size=[_itemNamelabel.text sizeWithAttributes:attrs]; [self.itemNamelabel setFrame:CGRectMake(40, 10, size.width, 20)];
近期评论