美文网首页
NSString+Extent

NSString+Extent

作者: 特喵了个咪的猫 | 来源:发表于2017-01-10 12:08 被阅读0次

    - (CGFloat)heightWithText:(NSString *)text font:(UIFont*)font width:(CGFloat)width;

    - (CGFloat)heightWithFontSize:(CGFloat)size width:(CGFloat)width;



    - (CGFloat)heightWithText:(NSString *)text font:(UIFont *)font width:(CGFloat)width{

    NSDictionary *attributes = @{NSFontAttributeName:font};

    CGSize contentSize = [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributes context:nil].size;

    return contentSize.height;

    }

    -(CGFloat)heightWithFontSize:(CGFloat)size width:(CGFloat)width{

    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:size]};

    CGSize contentSize = [self boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading) attributes:attributes context:nil].size;

    return contentSize.height;

    }

    相关文章

      网友评论

          本文标题:NSString+Extent

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