Swift中的NSTextField行间距

时间:2016-07-08 01:08:40

标签: swift macos cocoa nstextfield

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

1 个答案:

答案 0 :(得分: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)