我在菜单栏中为我的按钮创建了一个自定义视图。因为我把它添加为子视图,所以当点击按钮时,它就像电池一样点击了效果:
现在我看到我可以覆盖mouseDown效果和mouseUp来手动执行此效果。有谁知道我怎么能添加这种效果?
编辑:例如,它可以解决我的问题,如果我知道如何在我的自定义NSView中绘制矩形的背景
答案 0 :(得分:0)
好的,我真的得到了这个问题的帮助:Best way to change the background color for an NSView
override func mouseDown(with theEvent: NSEvent) {
switcher = true
needsDisplay = true
}
override func mouseUp(with theEvent: NSEvent)
{
switcher = false
needsDisplay = true
}
override func draw(_ dirtyRect: NSRect) {
[do the usual thing]
if (switcher == true)
{
// color picked the color of the normal mouseDown event
let c1 = NSColor(calibratedRed: 48.0/255.0, green: 91.0/255.0, blue: 178.0/255.0, alpha: 1.0)
c1.setFill()
self.frame.fill()
myrect?.fill()
NSColor.clear.setFill()
[do the usual thing]
}
}