iOS 调整一个label 上的字体间距与行间距

时间:2023-02-01 08:28:59

 // 修改支付金额换行

        NSString * cLabelStr = [NSString stringWithFormat:@"本直播是付费产品,您已体验%ld分钟\n您需要支付%@元流量费才可以继续观看!",(long)vc.live_free_time,[BSUserData sharedUserData].creatRoomInfoDict[@"price_online"]];

        NSMutableAttributedString * mutableStr = [[NSMutableAttributedString alloc]initWithString:cLabelStr];

        long number = 2.0f;//字间距

        CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt8Type,&number);

        [mutableStr addAttribute:(id)NSKernAttributeName value:(__bridge id)num range:NSMakeRange(0,[cLabelStr length])];

        CFRelease(num);

        // 行间距15

        NSMutableParagraphStyle * paragrapStyle = [[NSMutableParagraphStyle alloc]init];

        [paragrapStyle setLineSpacing:15];

        [mutableStr addAttribute:NSParagraphStyleAttributeName value:paragrapStyle range:NSMakeRange(0, [cLabelStr length])];

        [_continueCourseAlertView.contentLab setAttributedText:mutableStr];