#import "MyLabel.h" #import <CoreText/CoreText.h> @implementation MyLabel +(void)setLabel:(UILabel *)custonLabel andContenStr:(NSString *)content andlineSpace:(CGFloat)lineSpace andHeightSpace:(long)fontSpace{ NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:content]; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; [style setLineSpacing:lineSpace];//行间距 CFNumberRef num = CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt8Type,&fontSpace); [str addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(0, content.length)]; CFRelease(num);//字间距 [str addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [str length])]; [custonLabel setAttributedText:str]; } @end