swift - NSView mouseDown 填充矩形
问题描述
我在菜单栏中为我的按钮制作了一个自定义视图。因为我将它添加为子视图,所以当按钮被点击时,它消除了效果,就像这里的电池一样:
现在我看到我可以覆盖 mouseDown 效果和 mouseUp 来手动执行此效果。有谁知道我如何添加这种效果?
编辑:例如,如果我知道如何在自定义 NSView 中绘制矩形的背景,它将解决我的问题
解决方案
好的,由于这个问题的帮助,我实际上得到了它: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]
}
}
推荐阅读
- presto - Presto SQL 中 TO_CHAR() 的替代语法是什么?
- php - 如何在 PHP 中找到 2 维数组中的元素数?
- php - PHP IP 白名单
- java - 我可以直接将来自外部源的数据映射到数据库上吗?
- python - 在python中获取一个变量在函数外工作
- arrays - 程序输出比数组中实际元素数多 1
- unity3d - unity 如何组合每个对象名称?
- java - 如何从 class.getResource() 释放资源
- python - 如何替换引用相同的类似书面值(赋予它们相同的值)?
- macos - Chrome 在新选项卡中将下载链接作为文件打开,而不是在 mac os 上下载文件