开发者

How to create a NSImageView with a rounded corner?

开发者 https://www.devze.com 2023-02-04 20:18 出处:网络
Current开发者_开发技巧ly now i want to create a round corner NSImageView,i am a newb,how to ?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

Current开发者_开发技巧ly now i want to create a round corner NSImageView,i am a newb,how to ?


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号