iOS

计算文本高度

2019-01-16  本文已影响0人  CYC666

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;

上一篇下一篇

猜你喜欢

热点阅读