Label改变行间距和字间距
2017-01-20 本文已影响21人
虫yu
NSString *text = label.text;
UIFont *font = label.font;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;// 折行方式也可以设置最后一行的结束形式,例如,以...结尾
paragraphStyle.lineSpacing = 1.8;// 改变行间距
NSDictionary *attributes = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paragraphStyle.copy, NSKernAttributeName:@(0.6)};// 改变字间距
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text attributes:attributes];
self.brandInfo.attributedText = attributedString;
// [self.brandInfo sizeToFit];// 改变labl的尺寸,如果是需要显示限定行数(label.numberOfLines=2;),不写此行