美文网首页
计算文字宽度和高度

计算文字宽度和高度

作者: LGirl | 来源:发表于2016-09-01 14:46 被阅读352次

计算文字宽度

NSString *content = @"欢迎来到北京";
CGSize size =[content sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]}];

计算文字高度

NSString *str = @"我爱北京天安门";
CGRect textRect = [str boundingRectWithSize:CGSizeMake(200, 2000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil];

相关文章

网友评论

      本文标题:计算文字宽度和高度

      本文链接:https://www.haomeiwen.com/subject/jxocettx.html