您的位置:首页 > 移动开发 > Swift

Swift/OC - 设置行间距

2017-09-18 14:38 351 查看
这个没什么好讲的,直接上代码,知道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)];


有问题请发送邮件到:584379066@qq.com , 请备注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息