富文本

作者: 寒雨晚风 | 来源:发表于2019-06-14 17:10 被阅读0次

1、NSForegroundColorAttributeName  字体颜色

 NSMutableAttributedString * AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@/份 %@/份 ",list.shop_price,list.church_shop_price]];

        [AttributedStraddAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,list.shop_price.length+1)];

     [AttributedStraddAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(list.shop_price.length+3,list.church_shop_price.length+1)];

运行结果

2.插入图片  中划线

 NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",model.title]];

         //NSTextAttachment可以将要插入的图片作为特殊字符处理

         NSTextAttachment *attch = [[NSTextAttachment alloc] init];

         //定义图片内容及位置和大小

              attch.image= [UIImageimageNamed:@"淘宝"];

         attch.bounds=CGRectMake(0, 0, 13.5, 13.5);

         //创建带有图片的富文本

         NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];

         //将图片放在最后一位

         //[attri appendAttributedString:string];

         //将图片放在第一位

         [attriinsertAttributedString:string atIndex:0];

         //用label的attributedText属性来使用富文本

         commonCell.titleLab.attributedText= attri;

NSStrikethroughStyleAttributeName   中划线

  NSMutableAttributedString * AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥%@ ¥%@",zk_final_price,reserve_price]];

         [AttributedStraddAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(zk_final_price.length+2,reserve_price.length+1)];

         [AttributedStraddAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(zk_final_price.length+2,reserve_price.length+1)];

         commonCell.priceLab.attributedText= AttributedStr;

  [AttributedStraddAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:20.0f] range:NSMakeRange(6,payPrice.length+1)];  字体放大 加粗

相关文章

网友评论

      本文标题:富文本

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