In my application for Mac I want to show some info text when the users moves the mouse pointer over a button. Something like this:
How can I achieve this correctly?
Thanks in advance.
This works for me in Xcode 6.2:
In the Identity Inspector(the pane on the right hand side in the image below), in the Tool Tip
section enter "Sad face":
To programmatically add a custom tooltip in Swift, subclass the corresponding view
var trackingArea: NSTrackingArea!
Add a tracking area for the view
let opts: NSTrackingAreaOptions = ([NSTrackingAreaOptions.MouseEnteredAndExited, NSTrackingAreaOptions.ActiveAlways])
trackingArea = NSTrackingArea(rect: bounds, options: opts, owner: self, userInfo: nil)
self.addTrackingArea(trackingArea)
Mouse entered Event
override func mouseEntered(theEvent: NSEvent) {
self.tooltip = "Sad face : Select the option for very poor"
}
Or you can make a separate tooltip for each range of a string: https://stackoverflow.com/a/18814112/308315
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With