本文主要是介绍iOS-UILabel调整行间距,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方法:
封装了以下方法,传入参数调整行间距
- (NSAttributedString *)getAttributedStringWithString:(NSString *)string lineSpace:(CGFloat)lineSpace {NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];paragraphStyle.lineSpacing = lineSpace;// 调整行间距NSRange range = NSMakeRange(0, [string length]);[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];return attributedString;
}
调用:
NSAttributedString *attstring = [self getAttributedStringWithString:@"12345678901234567890" lineSpace:3];
[_label setAttributedText:attstring];
这篇关于iOS-UILabel调整行间距的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!