마우스 오버 이벤트에서 강조 표시된 버튼을 완료하려고합니다. 그래서 나는 NSButton
을 서브 클래 싱했다. 여기에는 NSTrackingArea
과 - (void)mouseEntered:(NSEvent *)event
과 - (void)updateTrackingAreas
이있다.NSButton NSTrackingArea - 추적이 작동하지 않습니다.
CalendarTile *button = [[CalendarTile alloc] init];
[button setFrame:CGRectMake(point_x, point_y, button_frame_width, button_frame_height)];
[button setBordered:NO];
[button setBezelStyle:NSRegularSquareBezelStyle];
[button setButtonType:NSMomentaryChangeButton];
[button setFont:[NSFont fontWithName:@"Avenir Next" size:40]];
[button setAlignment:NSCenterTextAlignment];
[button setTitle:[NSString stringWithFormat:@"%i", i]];
[button setTextColor:[NSColor colorWithCalibratedRed:(float)62/255 green:(float)62/255 blue:(float)62/255 alpha:1.0]];
[arrayWithButtons addObject:button];
...
for (CalendarTile *btn in arrayWithButton) {
[self addSubview:btn];
}
을 그리고 이것은 서브 클래스 - CalendarTile.m : 버튼의
창조 그렇게 보이는 (I 수집 배열을 사용 있도록 루프에서의)
@implementation CalendarTile
- (void)updateTrackingAreas
{
[super updateTrackingAreas];
if (trackingArea)
{
[self removeTrackingArea:trackingArea];
}
NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow;
trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:options owner:self userInfo:nil];
[self addTrackingArea:trackingArea];
}
- (void)mouseEntered:(NSEvent *)event
{
[self setImage:[NSImage imageNamed:@"highlight.png"]];
NSLog(@"HIGHLIGHT");
}
이 글은 말을해야 마우스 오버시에는 "HIGHLIGHT"가 기록됩니다. 슬프게도 그렇지 않습니다.
도와 주시겠습니까? 내가 틀린 게 뭐야?
NSZeroRect로 추적 영역을 초기화 하시겠습니까? – TheAmateurProgrammer
자,이 문제에 따라 문제를 해결했습니다 : http://stackoverflow.com/questions/7889419/cocoa-button-rollovers-with-mouseentered-and-mouseexited –