富文本

作者: 阿龍飛 | 来源:发表于2016-09-06 23:26 被阅读25次

    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];
    
    

    相关文章

      网友评论

          本文标题:富文本

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