【发布时间】:2016-07-08 01:08:39
【问题描述】:
如何使用 Swift 或在 Interface Builder 中以编程方式设置多行 NSTextField 的行距?
【问题讨论】:
标签: swift macos cocoa nstextfield
如何使用 Swift 或在 Interface Builder 中以编程方式设置多行 NSTextField 的行距?
【问题讨论】:
标签: swift macos cocoa nstextfield
您可以使用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)
【讨论】: