美文网首页
MAC:NSImageView

MAC:NSImageView

作者: L柠_檬 | 来源:发表于2016-08-19 15:40 被阅读145次
目录
  1.1 设置圆角
  1.2 添加点击事件
1.1 设置圆角

NSImageView *imgView = [[NSImageView 
alloc]initWithFrame:CGRectMake(35, 100, 70, 70)];

//给图片赋值和iOS开发是一样的

imgView.image = [NSImage imageNamed:@"1"];

[self.view addSubview:imgView];


//设置圆角,wantLayer = YES 必须写在最前面。
imgView.wantsLayer = YES;

imgView.layer.cornerRadius = 35.0f;

imgView.layer.borderWidth = 2;

imgView.layer.borderColor = [NSColor greenColor].CGColor;

imgView.layer.masksToBounds = YES;

1.2 添加点击事件

//重写NSImageView方法
#import <Cocoa/Cocoa.h>

@interface DDImageView : NSImageView

typedef void(^BlockImageViewClicked) ();

@property (nonatomic , copy)BlockImageViewClicked blockImageViewClicked;

@end


#import "DDImageView.h"

@implementation DDImageView

- (id)initWithFrame:(NSRect)frameRect{
    
    if (self == [super initWithFrame:frameRect]) {
        
    }
    return self;
}
//重写
- (void)mouseDown:(NSEvent *)theEvent {
    
    if (self.blockImageViewClicked) {
        self.blockImageViewClicked();
    }
    
}

@end

相关文章

网友评论

      本文标题:MAC:NSImageView

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