Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a colored border around NSImage?

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!

like image 826
Eugene Gordin Avatar asked Oct 28 '13 21:10

Eugene Gordin


1 Answers

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];
like image 168
Hussain Shabbir Avatar answered Sep 21 '22 08:09

Hussain Shabbir