富文本

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

你可能感兴趣的:(富文本)