iOS中给特定位置字体加粗

1,347 阅读1分钟

一、在iOS中字符串文字加粗

@property(nonatomic,strong)UILabel *labelYZ;#pragma mark -给特定位置加粗

-(void)lwySetFontbold{
    //原字符串
    NSString * strAdvance = self.labelYZ.text;
    //截取最后一位之前的字符串
    NSString * str1Advance = [strAdvance substringWithRange:NSMakeRange(0, strAdvance.length-1)];
    //创建可变字符串
    NSMutableAttributedString * tempStrAdvance = [[NSMutableAttributedString alloc] initWithString:strAdvance];
//    NSRange tempStrAdvanceRang = [str1Advance rangeOfString:self.labelYZ.text];
    //给特定位置加粗
    [tempStrAdvance addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:13] range:NSMakeRange(5, str1Advance.length-5)];
    //返回
    self.labelYZ.attributedText = tempStrAdvance;