Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a NSImageView with a rounded corner?

Currently now i want to create a round corner NSImageView,i am a newb,how to ?

like image 456
NeXT5tep Avatar asked Jan 14 '11 02:01

NeXT5tep


People also ask

How do you round the corners of a view?

You can give it round corners by changing the cornerRadius property of the view's layer . and smaller values give less rounded corners. Both clipsToBounds and masksToBounds are equivalent. It is just that the first is used with UIView and the second is used with CALayer .


Video Answer


2 Answers

This is what I used in Swift:

imageView.wantsLayer = true
imageView.layer?.borderWidth = 1.0
imageView.layer?.borderColor = NSColor.red.cgColor
imageView.layer?.cornerRadius = 25.0
imageView.layer?.masksToBounds = true
like image 150
madx Avatar answered Sep 30 '22 14:09

madx


I don't know if this will work so please try it and we'll cross our fingers. On the iPhone you can use the CALayer of any UIView (the NSView counterpart in iOS) to get rounded corners. Based on the reference docs it appears that NSView supports this but again you'll have to try it. Please let me know if it works.

NSImageView *view = your view;

[view setWantsLayer: YES];  // edit: enable the layer for the view.  Thanks omz

view.layer.borderWidth = 1.0;
view.layer.cornerRadius = 8.0;
view.layer.masksToBounds = YES;

You can also modify the borderWidth and borderColor properties.

like image 44
par Avatar answered Oct 01 '22 14:10

par