[英]How do you make text appear when mouse is hovering?
I was wondering if anyone knew how to make text appear when hovering over an element, in this case, an NSImage?我想知道是否有人知道如何在将鼠标悬停在元素上时显示文本,在这种情况下是 NSImage? The best example of what I'm talking about is when you hover over an application when it's in your dock and the name of it appears.
我所说的最好的例子是当你将鼠标悬停在你的 Dock 中的应用程序上并且它的名称出现时。 Here's an image of what I'm talking about:
这是我正在谈论的图像:
Text when hovering over doc悬停在文档上时的文本
What you need is a NSButton
which can be initialised with your NSImage
.你需要的是一个
NSButton
,它可以用你的NSImage
初始化。 You just need to set the button toolTip
property:您只需要设置按钮
toolTip
属性:
let button = NSButton(image: buttonImage, target: self, action: #selector(imageAction))
button.toolTip = "Image action info"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.