ChrisRockC / MyWiki

点-线-面
0 stars 0 forks source link

NSMutableAttributedString #163

Open ChrisRockC opened 7 years ago

ChrisRockC commented 7 years ago

NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:str]; [text addAttribute:NSForegroundColorAttributeName value:kThemeGreen range:NSMakeRange(0, model.commentUserName.length)]; [text addAttribute:NSForegroundColorAttributeName value:kThemeGreen range:NSMakeRange(model.commentUserName.length + 2, model.commentByUserName.length)]; self.contentLabel.attributedText = text;

ChrisRockC commented 7 years ago

NSString str = [NSString stringWithFormat:@"¥%@",commentModel.goodsPrice]; NSMutableAttributedString attrString = [[NSMutableAttributedString alloc] initWithString:str]; UIFont font = [UIFont systemFontOfSize:12]; [attrString addAttribute:NSFontAttributeName value:font range:NSMakeRange(1,commentModel.goodsPrice.length-1)]; UIFont font1 = [UIFont systemFontOfSize:18]; [attrString addAttribute:NSFontAttributeName value:font1 range:NSMakeRange(0,1)]; [self.priceLabel setAttributedText:attrString];