uilabel行距.字間距

weixin_34050427發表於2016-06-12

cLabelString//字串

cLabel//UILabel事例

NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:cLabelString];

NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];

[paragraphStyle1 setLineSpacing:8];

[attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [cLabelString length])];

[cLabel setAttributedText:attributedString1];

[cLabel sizeToFit];

[self.view addSubview:cLabel];


//字間距

#import <CoreText/CoreText.h>


NSMutableAttributedString*attributedString =[[NSMutableAttributedStringalloc]initWithString:@"使用者登入"];

longnumber =2.5f;//間距

CFNumberRefnum =CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt8Type,&number);

[attributedStringaddAttribute:(id)kCTKernAttributeNamevalue:(__bridgeid)numrange:NSMakeRange(0,[attributedStringlength])];

CFRelease(num);

相關文章