使用TTTAttributedLabel添加文字边框

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;

 }];


使用TTTAttributedLabel添加文字边框_第1张图片

效果如下:


使用TTTAttributedLabel添加文字边框_第2张图片

你可能感兴趣的:(使用TTTAttributedLabel添加文字边框)