Swift/OC - 设置行间距

这个没什么好讲的,直接上代码,知道swift中设置行间距的样式就行。附加上OC版设置:

Swift4.0

 let paragraphStye = NSMutableParagraphStyle()
 //调整行间距
 paragraphStye.lineSpacing = 5.0
 paragraphStye.lineBreakMode = NSLineBreakMode.byWordWrapping
 let attributedString = NSMutableAttributedString.init(string: self.contentLab.text!, attributes: [NSAttributedStringKey.paragraphStyle:paragraphStye])
 self.contentLab.attributedText = attributedString

OC版:
NSMutableAttributedString *attriText = [[NSMutableAttributedString alloc] initWithString:content];
NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
[paragraphStyle setLineSpacing:5];
[paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];
[attriText addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],NSForegroundColorAttributeName:UIColorFromRGB(0x333333,1),NSParagraphStyleAttributeName:paragraphStyle} range:NSMakeRange(0, content.length)];

有问题请发送邮件到:[email protected] , 请备注

你可能感兴趣的:(Swift)