13

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:

enter image description here

How can I achieve this correctly?

Thanks in advance.

user3065901
  • 4,678
  • 11
  • 30
  • 52
  • Hey, could you show your code for how you make the image round? – 7stud Apr 29 '15 at 18:15
  • Sorry but it is only an example image from google :S, I have no code for that. – user3065901 Apr 30 '15 at 11:00
  • But images from google, like all images, are square. For instance, the images of sad faces on google generally consist of a round face and a white background--and the face and background together form a square. If I specify one of those images in the Attributes Inspector for the Button, then my window displays a square image(a round face plus the white background). So, you must be doing something in your code to make the image clip to the button's shape. I am not able to accomplish that, and I was wondering how you did it. Or, did you change the white background to gray to match the window? – 7stud Apr 30 '15 at 17:12
  • You have to get png image without background or edit someone to get only the round form. Try to set off the bordered option and the scaling of image to proportionally down – user3065901 May 05 '15 at 14:38

4 Answers4

24

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":

enter image description here

7stud
  • 46,922
  • 14
  • 101
  • 127
  • Hi, If I want make fancy popup view, like hover on video playback progress bar [-----------], it show a screenshot of that time. any idea? make a .xib file and design popup view in that? how to show it? – NamNamNam May 07 '19 at 11:47
5

In Interface-Builder you can set a 'tooltip' for most objects, including NSButton (Open the Inspector, then choose the "Help" section). However, if you're using a NSToolbar, this also has tooltips; you may choose to do this programmatically. Try typing setToolTip in your source, then option-double-click it for more information. (option=alternate).

4

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

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Barath
  • 1,656
  • 19
  • 19
  • 2
    Overkill. Use the `toolTip` property inherited from `NSView`. – adib Aug 09 '17 at 22:38
  • While true that you can simply use the toolTip property inherited from NSView, this does not work when you are already overriding the mouseEntered property. In this case, it seems that you have to set the toolTip property manually... – Steve Begin Sep 27 '19 at 14:27
3

You can also do it programmatically.

(Assume someButton is your NSButton object)

[someButton setToolTip:@"Sad face: Select this option for \"Very poor\""];
Will
  • 1,697
  • 17
  • 34