private lazy var centerContentLab: UILabel = {
    let lab = UILabel()
    lab.textColor = R.color.text_main()
    lab.font = .yd.footnoteRegular
    lab.lineBreakMode = .byWordWrapping
    lab.numberOfLines = 0
    
  
    
    return lab
}()

    // 设置行间距
    let paragraphStyle = NSMutableParagraphStyle()
    paragraphStyle.lineSpacing = 4 // 设置行间距为4
    let attributes: [NSAttributedString.Key: Any] = [
        .paragraphStyle: paragraphStyle
    ]
centerContentLab.attributedText = NSAttributedString(string: text, attributes: attributes)

 

 

多属性设置

let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 4 // 设置行间距为4
let attributes: [NSAttributedString.Key: Any] = [
    .paragraphStyle: paragraphStyle,
    .font: lab.font,  // 使用原来设置的字体
    .foregroundColor: lab.textColor  // 使用原来设置的文本颜色
]

centerContentLab.attributedText = NSAttributedString(string: text, attributes: attributes)

 

posted on 2025-08-27 13:58  懂事长qingzZ  阅读(7)  评论(0)    收藏  举报