为什么AttributedString只能与String一起使用,而不能与labelWithAttributedString一起使用?

时间:2019-04-21 16:48:54

标签: swift macos

我有一些AttributedKeys分配给String对象,而相同的Keys分配给带有labelWithAttributedString实例化的标签-许多属性都转换为两个对象,但是ParagraphStyle的属性不会继承到标签-我已经查看了文档,但似乎无法理解原因-我发布了一些Playground代码来显示

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...

段落行为(行高和结尾的省略号)显示在字符串中,而不显示在标签中。

0 个答案:

没有答案
相关问题