Skip to content

Instantly share code, notes, and snippets.

@TomLiu
Created June 18, 2012 13:41
Show Gist options
  • Save TomLiu/2948431 to your computer and use it in GitHub Desktop.
Save TomLiu/2948431 to your computer and use it in GitHub Desktop.
//
// TMButton.h
// TMButton
//
// Created by 61 on 6/17/12.
// Copyright (c) 2012 61. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface TMButton : NSButton{
NSTrackingArea *_trackingArea;
}
@property (nonatomic, strong) NSImage *originImage;
@property (nonatomic, strong) NSImage *hoverImage;
@end
//
// TMButton.m
// TMButton
//
// Created by 61 on 6/17/12.
// Copyright (c) 2012 61. All rights reserved.
//
#import "TMButton.h"
@implementation TMButton
@synthesize originImage;
@synthesize hoverImage;
- (void)mouseEntered:(NSEvent *)theEvent
{
[self setImage:self.hoverImage];
[self display];
}
- (void)mouseExited:(NSEvent *)theEvent
{
[self setImage:self.originImage];
[self display];
}
- (void)updateTrackingAreas {
[super updateTrackingAreas];
if (_trackingArea)
{
[self removeTrackingArea:_trackingArea];
}
NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
_trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:options owner:self userInfo:nil];
[self addTrackingArea:_trackingArea];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment