美文网首页iOS
计算文本高度

计算文本高度

作者: CYC666 | 来源:发表于2019-01-16 16:31 被阅读0次

NSMutableParagraphStyle *muStyle = [[NSMutableParagraphStyle alloc]init];

    muStyle.lineSpacing=3;//设置行间距离

    muStyle.alignment = NSTextAlignmentLeft;//对齐方式

    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:adWord];

    [attrStringaddAttribute:NSFontAttributeNamevalue:MaterialFontrange:NSMakeRange(0, attrString.length)];

    [attrStringaddAttribute:NSParagraphStyleAttributeNamevalue:muStylerange:NSMakeRange(0, attrString.length)];

    NSDictionary *attributes = @{NSFontAttributeName:MaterialFont,NSParagraphStyleAttributeName:muStyle};

    CGFloat h = [adWord boundingRectWithSize:CGSizeMake(kScreenWidth - 20*2, CGFLOAT_MAX)

                                     options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading

                                  attributes:attributescontext:nil].size.height;

相关文章

网友评论

    本文标题:计算文本高度

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