首页 > 其他 > 详细

label 设置行间距 字间距

时间:2015-11-14 06:25:21      阅读:366      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!