label 设置行间距 字间距

#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

 

posted @ 2015-11-14 04:22  Mac-one  阅读(598)  评论(0编辑  收藏  举报