美文网首页
macOS开发之鼠标箭头样式

macOS开发之鼠标箭头样式

作者: chasitu | 来源:发表于2021-08-31 11:37 被阅读0次

我们再开发macOS客户端的时候会有修改鼠标箭头样式的需求,我们今天就解决问题,就是这个类NSCursor,代码量比较少,直接上代码

核心思路:给当前类添加鼠标监听,然后修改鼠标样式

#import "SHButton.h"

@interface SHButton ()
@property (nonatomic , strong) NSTrackingArea *trackingArea;
@end
@implementation SHButton
-(void)updateTrackingAreas{
    if (self.trackingAreas.count > 0) {
        [self removeTrackingArea:_trackingArea];
    }
    NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited|NSTrackingActiveInKeyWindow;
    _trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
                                                                options:options
                                                                  owner:self
                                                               userInfo:nil];
    [self addTrackingArea:_trackingArea];
}

-(void)mouseEntered:(NSEvent *)theEvent{
    [[NSCursor pointingHandCursor] set];
}

-(void)mouseExited:(NSEvent *)theEvent{
    [[NSCursor arrowCursor] set];
}
@end
  • updateTrackingAreas这个方法类似于我们iOS的layoutSubviews调用频繁,所以需要清除之前的监听
  • 下面的两个回调方法就不多解释了,是鼠标监听回调
  • [[NSCursor pointingHandCursor] set]这里是修改鼠标样式的代码
  • 鼠标的其它样式如下:
@property (class, readonly, strong) NSCursor *arrowCursor;
@property (class, readonly, strong) NSCursor *IBeamCursor;
@property (class, readonly, strong) NSCursor *pointingHandCursor;
@property (class, readonly, strong) NSCursor *closedHandCursor;
@property (class, readonly, strong) NSCursor *openHandCursor;
@property (class, readonly, strong) NSCursor *resizeLeftCursor;
@property (class, readonly, strong) NSCursor *resizeRightCursor;
@property (class, readonly, strong) NSCursor *resizeLeftRightCursor;
@property (class, readonly, strong) NSCursor *resizeUpCursor;
@property (class, readonly, strong) NSCursor *resizeDownCursor;
@property (class, readonly, strong) NSCursor *resizeUpDownCursor;
@property (class, readonly, strong) NSCursor *crosshairCursor;
@property (class, readonly, strong) NSCursor *disappearingItemCursor;
@property (class, readonly, strong) NSCursor *operationNotAllowedCursor API_AVAILABLE(macos(10.5));
@property (class, readonly, strong) NSCursor *dragLinkCursor API_AVAILABLE(macos(10.6));
@property (class, readonly, strong) NSCursor *dragCopyCursor API_AVAILABLE(macos(10.6));
@property (class, readonly, strong) NSCursor *contextualMenuCursor API_AVAILABLE(macos(10.6));
@property (class, readonly, strong) NSCursor *IBeamCursorForVerticalLayout API_AVAILABLE(macos(10.7));

NSCursor这个类还有其它的一些方法,这里就不罗列了,有感兴趣的小伙伴可以自行查阅

相关文章

  • macOS开发之鼠标箭头样式

    我们再开发macOS客户端的时候会有修改鼠标箭头样式的需求,我们今天就解决问题,就是这个类NSCursor,代码量...

  • day11-CSS-三大特性

    谷歌开发者工具 展示样式--三个点 小箭头--防止鼠标的时候,可以知道是哪行标签 手机--响应式开发 style-...

  • CSS-用户界面样式

    鼠标样式 cursor属性default 小白箭头pointer 小手move 可以移动的十字箭头text ...

  • macOS应用开发之Objective-C系列-入门

    macOS应用开发之Objective-C系列(纯代码开发) 第一节,macOS开发入门之Hello MacOS ...

  • Chrome开发者工具——Elements

    Elements——元素面板 1、定位元素:鼠标点击箭头后,将鼠标放置到想查看具体样式的元素上 如果在测试的时候,...

  • 鼠标样式(cursor)

    规定要鼠标进入元素内容区域要显示的光标的类型 基本样式 default 箭头 pointer 小手 move 可移...

  • Mac鼠标样式设置

    在开发Mac App 时,经常需要变换鼠标样式。实现鼠标样式的变换需要用到两个类:NSCursor、NSTrack...

  • 使用Markdown画UML

    使用sequence 简单样式 复杂样式 mermaid 类型描述->实线无箭头->虚线无箭头->>带箭头的实线-...

  • macOS开发之监听鼠标移入和移出

    简单说一下场景吧,今天遇到的需求就是鼠标移入修改颜色,移出鼠标颜色恢复的,之前做iOS开发的经验来看就是去相关控件...

  • Mac App开发资料

    MacOS 开发 - NSTableView (纯代码)伊织__MacOSmacOS开发之NSTableView的...

网友评论

      本文标题:macOS开发之鼠标箭头样式

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