UILabel 设置字体行间距
2017.07.20
Talent•C
 热度
℃
作者Talent•C
转载请注明出处
在iOS开发中经常会用到UIlabel来展示一些文字性的内容,但是默认的文字排版会觉得有些挤,为了更美观也更易于阅读我们可以通过某些方法将UIlabel的行间距和字间距按照需要调节。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| - (NSAttributedString *)handleTextWithFont:(UIFont *)font textString:(NSString *)str { NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init]; paraStyle.lineBreakMode = NSLineBreakByTruncatingTail; paraStyle.alignment = NSTextAlignmentLeft; paraStyle.lineSpacing = 9; paraStyle.hyphenationFactor = 1.0; paraStyle.firstLineHeadIndent = 0.0; paraStyle.paragraphSpacingBefore = 0.0; paraStyle.headIndent = 0; paraStyle.tailIndent = 0; NSDictionary *dic = @{NSFontAttributeName:font, NSParagraphStyleAttributeName:paraStyle }; NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic]; return attributeStr; }
|