NSTextField line spacing in Swift

I have a wrapper label (multi-line label) in my application, which requires setting line spacing. How do I set the line spacing for this NSTextField using Swift or Interface Builder?

+5
source share
1 answer

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

  let title:String = "Your text" let textParagraph:NSMutableParagraphStyle = NSMutableParagraphStyle() textParagraph.lineSpacing = 10.0 /*this sets the space BETWEEN lines to 10points */ textParagraph.maximumLineHeight = 12.0/*this sets the MAXIMUM height of the lines to 12points */ let attribs = [NSAttributedStringKey.paragraphStyle:textParagraph] let attrString:NSAttributedString = NSAttributedString.init(string: title, attributes: attribs) titleTextField.attributedStringValue = attrString 
0
source

All Articles