富文本

NSAttributeString使用介绍http://www.jianshu.com/p/cfd472e5f78a

F8F1AC3B-93E6-4264-8750-B427D2898CFF.png

NSMutableAttributedString

   UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 100)];
    lab.numberOfLines = 0;
    NSString * str = @"冰与火的世界冰与火的世界冰与火的世界冰与火的世界冰与火的世界";
    NSMutableDictionary *arrts = [NSMutableDictionary dictionary];
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:str attributes:arrts];
    //字体颜色
    [attStr setAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor]} range:NSMakeRange(0, 6)];
    //字体颜色大小
    [attStr setAttributes:@{NSForegroundColorAttributeName : [UIColor redColor],NSFontAttributeName : [UIFont systemFontOfSize:30]} range : NSMakeRange(24, 6)];
    //行距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 16;
    NSRange range = NSMakeRange(0, attStr.length);
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
    lab.attributedText = attStr;
    [self.view addSubview:lab];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容