美文网首页
mac开发-----鼠标悬停事件(NSButton,NSImag

mac开发-----鼠标悬停事件(NSButton,NSImag

作者: MonkeyHan | 来源:发表于2017-02-03 17:35 被阅读116次

    很简单

    #import"mouseView.h"

    @implementation mouseView

    - (id)initWithFrame:(NSRect)frame {

    self = [super initWithFrame:frame];

    if (self) {

    // Initialization code here.

    }

    return self;

    }

    - (void)drawRect:(NSRect)dirtyRect {

    NSLog(@"have draw");

    if (flag==0) {

    [[NSColor redColor] set]; //设置颜色

    NSRectFill(dirtyRect);

    } else {

    [[NSColor yellowColor] set]; //设置颜色

    NSRectFill(dirtyRect);

    flag=0;

    }

    //填充rect区域.

    }

    - (void)viewDidMoveToWindow {

    [self addTrackingRect:[self bounds] owner:self userData:nilassumeInside:NO];

    }

    //[cursor set] make the current cursor change

    - (void)mouseEntered:(NSEvent *)theEvent

    {

    flag=1;

    NSCursor *cursor = [NSCursor pointingHandCursor];

    [cursor set];

    [selfsetNeedsDisplay:YES];

    }

    //[cursor set] make the current cursor change

    - (void)mouseExited:(NSEvent *)theEvent {

    flag=0;

    NSCursor *cursor = [NSCursor arrowCursor];

    [cursor set];

    [self setNeedsDisplay:YES];

    }

    @end

    相关文章

      网友评论

          本文标题:mac开发-----鼠标悬停事件(NSButton,NSImag

          本文链接:https://www.haomeiwen.com/subject/owfevttx.html