iOS开发中的富文本

 

  1. 改变指定字符的颜色

    NSString * text = [NSString stringWithFormat:@"%@米",distance];

    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:text];

    [attributedStr addAttribute:NSForegroundColorAttributeName value:blackTextColor range:NSMakeRange(text.length -1,1)];

    cell.labelright.attributedText = attributedStr;

 

  2.在价格中间加横线

    NSString * text = [NSString stringWithFormat:@"¥ %@",[sourseDic objectForKey:@"originalPrice"]];

    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString: text];

    [attrStr addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, text.length)];

    cell.labelOldPrice.attributedText = attrStr;

 

posted @ 2017-05-18 14:22  日月哥哥  阅读(357)  评论(0)    收藏  举报