I have some AttributedKeys assigned to a String object and the same Keys attributed to a label that was instantiated with labelWithAttributedString - many attributes translate to both objects, but the ParagraphStyle ones do not carry over to the label - I've looked in the docs but can't seem to understand why - I'm posting some Playground code to show

var fontHeight:CGFloat = 36.0
var baseFont = NSFont(name: "Raleway", size: fontHeight)
var fontColor = NSColor.blue
var myParagraphStyle = NSMutableParagraphStyle()
myParagraphStyle.lineBreakMode = .byTruncatingTail
myParagraphStyle.minimumLineHeight = fontHeight

var backgroundColor = NSColor.red
var attributeDictionary = [NSAttributedStringKey.font: baseFont,           NSAttributedStringKey.foregroundColor: fontColor, NSAttributedStringKey.backgroundColor: backgroundColor, NSAttributedStringKey.paragraphStyle: myParagraphStyle]
var myString = NSAttributedString(string: "Hello there as if you didn't know, this is a long text string", attributes: attributeDictionary)

var myLabel2 =  NSTextField(labelWithAttributedString: myString)

Playground showing results...

The paragraph behavior (line height and the trailing ellipsis) show in the String but not the label.

0 Answers