您的位置:首页 > 其它

label 设置行间距 字间距

2015-11-14 04:22 447 查看
#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: