码迷,mamicode.com
首页 > 其他好文 > 详细

label 设置行间距 字间距

时间:2015-11-14 06:28:37      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:

#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

 

label 设置行间距 字间距

标签:

原文地址:http://www.cnblogs.com/machealking/p/4963730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!