//获取字符串的宽度
-(float)widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height
{
    UIColor  *backgroundColor=[UIColor blackColor];
    UIFont *font=[UIFont boldSystemFontOfSize:fontSize];
    CGRect sizeToFit = [value boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{
                                                                                                                                             NSForegroundColorAttributeName:backgroundColor,
                                                                                                                                             NSFontAttributeName:font
                                                                                                                                             } context:nil];
    
    return sizeToFit.size.width;
}
//获得字符串的高度
-(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width
{
    UIColor  *backgroundColor=[UIColor blackColor];
    UIFont *font=[UIFont boldSystemFontOfSize:18.0];
    CGRect sizeToFit = [value boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{
                                       NSForegroundColorAttributeName:backgroundColor,
                                       NSFontAttributeName:font
                                       } context:nil];
    return sizeToFit.size.height;
}

 

相关文章:

  • 2021-09-07
  • 2021-12-12
  • 2018-04-10
  • 2021-11-11
  • 2021-07-25
  • 2021-09-07
  • 2021-11-03
猜你喜欢
  • 2021-11-01
  • 2021-10-29
  • 2021-12-28
  • 2021-10-27
  • 2021-04-12
  • 2021-10-27
  • 2021-12-18
  • 2021-12-18
相关资源
相似解决方案