Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTextField Line Spacing in Swift

How do you set the line-spacing for a multi-line NSTextField programmatically with Swift or within the Interface Builder?

like image 935
user3225395 Avatar asked Jul 08 '16 01:07

user3225395


1 Answers

You can use NSAttributedString to modify this (Swift 4 example):

    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)
like image 111
Avi L Avatar answered Nov 17 '22 10:11

Avi L