子类 NSTextview 并插入下面的代码
-(void)mouseEntered:(NSEvent *)theEvent{
CALayer *lay = [self layer];
CGColorRef myColor=CGColorCreateGenericRGB(0, 0, 1, 1);
[lay setBorderColor:myColor];
[lay setBorderWidth:4];
//[self setWantsLayer:YES];
[self setLayer:lay];
[self makeBackingLayer];
//CGColorRelease(myColor);
}
-(void)mouseExited:(NSEvent *)theEvent{
CALayer *lay = [self layer];
CGColorRef myColor=CGColorCreateGenericRGB(0, 0, 1, 1);
[lay setBorderColor:myColor];
[lay setBorderWidth:0];
//[self setWantsLayer:YES];
[self setLayer:lay];
[self makeBackingLayer];
//CGColorRelease(myColor);
}
-(void)updateTrackingAreas{
[super updateTrackingAreas];
if (trackingArea){
[self removeTrackingArea:trackingArea];
[trackingArea release];
}
NSTrackingAreaOptions options = NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingActiveInKeyWindow;
trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:options owner:self userInfo:nil];
[self addTrackingArea:trackingArea];
}