I’m beginner of Cocoa Programming.
How can I change NSButton‘s title when cursor is on the button? (without clicking).
I’m beginner of Cocoa Programming. How can I change NSButton ‘s title when cursor
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you look at the class hierarchy for NSButton you’ll see that it derives from NSResponder which is the class that handles mouse events.
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/nsbutton_Class/Reference/Reference.html
Create a subclass of NSButton and override the following messages to set the title to what you want:
Add this to your initializer (Either awakeFromNib or your init message, depending on your usage):
Note that even when the mouse has not actually entered the tracking area the first time the title will display the exited message. You may want to add some state to your class to if you want a third title set before it enters the tracking area the first time.
EDIT: Maybe this will help.
Here is the header file “MyButton.h”:
Pretty standard stuff.
Here is my source file.