Simple mouseover effect on NSButton

后端 未结 7 705
Happy的楠姐
Happy的楠姐 2021-02-04 01:51

I am creating a custom NSButtonCell for a custom rendering.

Now, I want to have different aspect depending if the mouse is over the button or not. How can

7条回答
  •  花落未央
    2021-02-04 02:14

    You need to Subclass the NSButton class (or even better the NSButtonCell class). As Justin said if you put the two method

    - (void)mouseEntered:(NSEvent *)theEvent;
    - (void)mouseExited:(NSEvent *)theEvent;
    

    They should get called when the mouse enter and exit the area. You may also need to re create the tracking area, look here:

    - (void)updateTrackingAreas
    

    For fade in and fade out effect I played with animator and alpha value for example:

    [self animator]setAlphaValue:0.5]; 
    

提交回复
热议问题