NSString *sign=@"商城自营";
NSString *nameAttr=[NSString stringWithFormat:@"%@ %@",sign,listModel.goods_name];[self.titleLabel setText:nameAttr afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString){
NSRange sumRange = [[mutableAttributedString string] rangeOfString:sign options:NSCaseInsensitiveSearch];
[mutableAttributedString addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)[[UIColor grayColor] CGColor] range:sumRange];
//文字边框
[mutableAttributedString addAttribute:kTTTBackgroundStrokeColorAttributeName
value:[UIColor grayColor]
range:sumRange];
//文字边框大小
[mutableAttributedString addAttribute:kTTTBackgroundCornerRadiusAttributeName
value:@(2)
range:sumRange];
UIFont *boldSystemFont = [UIFont fontWithName:lmz_font_name02 size:16];
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL);
if (font) {
[mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)font range:sumRange];
CFRelease(font);
}
return mutableAttributedString;
}];
效果如下: