如何在NSImage周围绘制彩色边框? [英] How to draw a colored border around NSImage?

查看:257
本文介绍了如何在NSImage周围绘制彩色边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一些研究,但所有的答案,我得到的是iOS,如何在OSX应用程序中绘制一个彩色边框围绕NSImage?我尝试使用NSImage的imageView属性来设置它的边框宽度和颜色,但它似乎不工作...

I did some research but all the answers I got were for iOS, how can I draw a colored border around NSImage in OSX app? I tried using imageView property of NSImage to set it's border width and color, but it doesn't seem to be working...

任何帮助是非常感谢!

Any kind of help is highly appreciated!

推荐答案

尝试这样而不创建子类也是可能的。您还可以相应地设置宽度和半径: -

Try like this without creating subclass also it is possible. Also you can set the width ans radius accordingly:-

[imgView setWantsLayer:YES];
imgView.layer.borderWidth = 1.0;
imgView.layer.cornerRadius = 8.0;
imgView.layer.masksToBounds = YES;
CGColorRef color = CGColorRetain([NSColor colorWithCalibratedRed:0 green:100 blue:0 alpha:0.5f].CGColor);
[imgView.layer setBorderColor:color];

这篇关于如何在NSImage周围绘制彩色边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆