1.在@interface的位置添加
/// 当鼠标移动到控件时,是否显示"小手" @property (assign, nonatomic) BOOL isHandCursor;
2.完成方法
-(void)mouseEntered:(NSEvent *)theEvent{ if (_isHandCursor == NO) return; [[NSCursor pointingHandCursor] set]; } -(void)mouseExited:(NSEvent *)theEvent{ if (_isHandCursor == NO) return; [[NSCursor arrowCursor] set]; }
3.控件调用,用NSbutton举例
- (void)viewDidLoad { [super viewDidLoad]; NSbutton *btn = [[NSbutton alloc] initWithFrame:CGRectMake(10, 10, 100, 60)]; //选择小手是否出现 btn.isHandCursor = YES; [self.view addSubview:btn]; }