【问题标题】:NSTextField Line Spacing in SwiftSwift 中的 NSTextField 行间距
【发布时间】:2016-07-08 01:08:39
【问题描述】:

如何使用 Swift 或在 Interface Builder 中以编程方式设置多行 NSTextField 的行距?

【问题讨论】:

    标签: swift macos cocoa nstextfield


    【解决方案1】:

    您可以使用NSAttributedString 来修改它(Swift 4 示例):

        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineSpacing = 10.0  // sets the space BETWEEN lines to 10 points
        paragraphStyle.maximumLineHeight = 12.0 // sets the MAXIMUM height of the lines to 12 points
    
        let text = "Your text"
        let attributes = [.paragraphStyle: paragraphStyle]
        textField.attributedStringValue = NSAttributedString(string: text, attributes: attributes)
    

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多