1 富文本 的实现效果
2 方法的封装
- (void)makeValueStringChangeWithPrice:(NSString *)price unit:(NSString *)unit
{
NSString *str = [NSStringstringWithFormat:@"¥ %@元/%@",price,unit];
_valueLabel.text = str;
NSMutableString * subtitlelabelStr = [NSMutableStringstringWithFormat:@"¥ %@元/%@",price,unit];
_valueLabel.text = subtitlelabelStr;
NSMutableAttributedString *attributedString = [[NSMutableAttributedStringalloc] initWithString:_valueLabel.text];
[attributedString setAttributes:@{NSForegroundColorAttributeName:NF_Color_C19,NSFontAttributeName:[UIFontsystemFontOfSize:Near_Final_Font_T2]
}range:NSMakeRange(0, 2)];
NSRange tmpRange = [[[attributedString string] lowercaseString] rangeOfString:@"元"];
NSRange valueRange;
valueRange.location = 2;
valueRange.length = tmpRange.location-1;
[attributedString addAttributes:@{NSForegroundColorAttributeName:NF_Color_C19,NSFontAttributeName:[UIFontsystemFontOfSize:Near_Final_Font_T5]}range:valueRange];
NSRange unitRange;
unitRange.location = tmpRange.location+1;
unitRange.length = [_valueLabel.textlength]-unitRange.location;
[attributedString setAttributes:@{NSForegroundColorAttributeName:NF_Color_C19,NSFontAttributeName:[UIFontsystemFontOfSize:Near_Final_Font_T2]}range:unitRange];
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStylealloc] init];
paragraph.alignment = NSTextAlignmentRight;
[attributedString addAttribute:NSParagraphStyleAttributeNamevalue:paragraph range:NSMakeRange(0, [_valueLabel.textlength])];
_valueLabel.attributedText = attributedString;
_valueLabel.frame = CGRectMake(self.bounds.size.width-200-10, CGRectGetMinY(self.scoreLabel.frame)-10-_valueLabel.contentSize.height, 200, 16);
}