【发布时间】:2019-10-08 11:19:12
【问题描述】:
我正在尝试创建一个带有下划线标题的 NSButton。
@IBOutlet var myButton: NSButton!
let underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single]
let underlineAttributedString = NSAttributedString(string: "Button Title", attributes: underlineAttribute)
myButton.attributedTitle = underlineAttributedString
但我得到了错误:
<NSATSTypesetter: 0x600003719500>: Exception -[__SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x600000ca4060 raised during typesetting layout manager <NSLayoutManager: 0x100e1a140>
1 containers, text backing has 5 characters
selected character range {0, 0} affinity: upstream granularity: character
marked character range {0, 0}
Currently holding 5 glyphs.
Glyph tree contents: 5 characters, 5 glyphs, 1 nodes, 64 node bytes, 256 storage bytes, 320 total bytes, 64.00 bytes per character, 64.00 bytes per glyph
Layout tree contents: 5 characters, 5 glyphs, 0 laid glyphs, 0 laid line fragments, 1 nodes, 64 node bytes, 0 storage bytes, 64 total bytes, 12.80 bytes per character, 12.80 bytes per glyph, 0.00 laid glyphs per laid line fragment, 0.00 bytes per laid line fragment
, glyph range {0 5}. Ignoring...
一般情况下是否可以创建带下划线的标题?
谢谢!
【问题讨论】:
-
哈!看起来将 NSAttributedString.Key.underlineStyle 设置为 NSUnderlineStyle.single.rawValue 起到了作用......很奇怪......但感谢正确的方向
标签: swift xcode cocoa nsbutton