我在里面有 NSPopupButton NSToolbar
,borderder = false
它在突出显示时有一些颜色混合。如果我使用bordered = true
图像是用漂亮的深色叠加绘制的。
我正在尝试以与它相同的方式绘制突出显示的状态bordered=true
PS:NSButtonCellbordered = false
开箱即用。
bordered = true
我可以通过拥有和覆盖来实现这种行为,drawBezel
并且在那里什么都不做,但我想知道
我尝试过的事情:
- 亮点通过
- 室内背景风格
- 设置细胞属性
-
class ToolbarPopUpButtonCell : NSPopUpButtonCell {
override var isHighlighted: Bool {
get { return true }
set { super.isHighlighted = newValue }
}
override func drawImage(withFrame cellFrame: NSRect, in controlView: NSView) {
super.drawImage(withFrame: cellFrame, in: controlView)
}
//used in case bordered = true so we do nothing
override func drawBezel(withFrame frame: NSRect, in controlView: NSView) {
}
//doesn't work
override var interiorBackgroundStyle: NSView.BackgroundStyle
{
return .raised
}
}
class ToolbarPopUpButton: NSPopUpButton {
override func awakeFromNib() {
cell?.setCellAttribute(.cellLightsByBackground, to: 1)
}
override var intrinsicContentSize: NSSize {
return NSMakeSize(32 + 5, 32)
}
}
注意右边的图像适用于bordered = false
( NSButtonCell
)