我对如何子类化 NSPopUpButton
感到困惑,即我无法像在按钮上那样设置 attributedTitle
(以获取自定义字体、颜色和基线偏移)。
以下代码无效:
class CustomPopUpButton: NSPopUpButton {
required init?(coder: NSCoder) {
super.init(coder: coder)
self.wantsLayer = true
self.layerContentsRedrawPolicy = .OnSetNeedsDisplay
self.attributedTitle = NSAttributedString(string: self.title, attributes: [
NSFontAttributeName: NSFont(name: "Impact", size: 15)!,
NSForegroundColorAttributeName: NSColor(calibratedRed: 0.2, green: 0.270588235, blue: 0.031372549, alpha: 1),
NSBaselineOffsetAttributeName: 2
])
}
}
最佳答案
NSPopUpButton 显示选中的菜单项。当您设置菜单项的属性字符串时,弹出按钮将显示一个属性标题。
关于swift - NSPopUpButton 子类 attributedTitle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36926336/