简体   繁体   English

鼠标悬停时如何显示文本?

[英]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.

相关问题 当您在Swift iOS中单击按钮时,如何显示文本字段? - How to make a text field appear when you click a button in swift ios? 如何使模态视图出现在控制器外部? - How do you make a modal view appear outside of a controller? 如何使用JSQMessageViewController显示发件人显示名称? - How do you make the sender display name appear with JSQMessageViewController? 轻按视图时,如何显示键盘并开始编辑文本字段 - How do I make the keyboard appear and the text field begin editing when the view is tapped 选择文本字段时如何使键盘不出现? - How can I make a keyboard not appear when selecting a text field? 如何在应用加载时使viewController出现? - How do I make a viewController appear when app loads? 如何让 SwiftUI 中的文本在旋转框架的同时侧向显示? - How can you make Text in SwiftUI appear sideways while also rotating the frame? 如何在Swift中为iOS创建垂直文本UILabel和UITextView? - How do you make a vertical text UILabel and UITextView for iOS in Swift? 当文本长于标签宽度时,如何使 UILabel 文本在末尾显示省略号 - How to make UILabel text appear with ellipsis at the end when text is longer than label's width 如何在按钮上显示文字? -SpriteKit - How to make text appear on button? -SpriteKit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM