zoukankan      html  css  js  c++  java
  • 计算富文本的高度

    1.设置富文本

    - (CGFloat)textHeight :(NSString *)content{
        NSString *text = [CustomMethod transformString:content emojiDic:emojiDic];
        
        text = [NSString stringWithFormat:@"<font color='black' strokeColor='gray' face='Palatino-Roman'>%@",text];
        MarkupParser *wk_markupParser = [[MarkupParser alloc] init];
        NSMutableAttributedString* attString = [wk_markupParser attrStringFromMarkup: text];
        [attString setFont:[UIFont systemFontOfSize:16]];
        
      //设置文本的行高 CGFloat lineSpacing
    = 7.0; CTParagraphStyleSetting paragraphStyles[9] = { {.spec = kCTParagraphStyleSpecifierLineSpacing, .valueSize = sizeof(CGFloat), .value = (const void *)&lineSpacing} }; CTParagraphStyleRef paragraphStyle = CTParagraphStyleCreate(paragraphStyles, 9); NSMutableDictionary * mutableAttributes = [NSMutableDictionary dictionary]; [mutableAttributes setObject:(id)paragraphStyle forKey:(NSString *)kCTParagraphStyleAttributeName]; CFRelease(paragraphStyle); NSDictionary* attDic = [NSDictionary dictionaryWithDictionary:mutableAttributes]; [attString addAttributes: attDic range:NSMakeRange(0, [content length])]; CGSize size=[CommonCore adjustSizeWithAttributedString:attString maxWidth:WIDTHWITH(200)]; return size.height; }

    2、计算高度

    //计算富文本大小
    + (CGSize)adjustSizeWithAttributedString:(NSAttributedString *)attributedString maxWidth:(CGFloat)width {
        CTFramesetterRef framesetter =
        CTFramesetterCreateWithAttributedString((__bridge CFMutableAttributedStringRef)attributedString);
        
        CGSize maxSize = CGSizeMake(width, CGFLOAT_MAX);
        CGSize size = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, 0), NULL, maxSize, NULL);
        
        CFRelease(framesetter);
        
        return CGSizeMake(floor(size.width) + 1, floor(size.height) + 1);
    }
  • 相关阅读:
    Haproxy图解
    Keeplived 配制图解
    日志文件 的管理 logrotate 配置
    Haproxy+MYSQL 负载均衡 原创
    MySQL内存----使用说明全局缓存+线程缓存) 转
    MYSQL内存--------启动mysql缓存机制,实现命中率100% 转
    MYSQL SQL 审核工具 (inception安装步骤)
    MHA手动切换 原创4 (非交互式切换)
    MHA手动切换 原创2 (主参与复制)
    MHA手动在线切换主 原创3(主不参与复制)
  • 原文地址:https://www.cnblogs.com/tianlin106/p/5948581.html
Copyright © 2011-2022 走看看