9

目前我想创建一个圆角 NSImageView,我是新手,怎么做?

4

2 回答 2

30

我不知道这是否可行,所以请尝试一下,我们会交叉手指。在 iPhone 上,您可以使用CALayerany UIViewNSViewiOS 中的对应项)来获得圆角。根据参考文档,它似乎支持这一点,NSView但您必须再次尝试。请让我知道它是否有效。

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;

您还可以修改borderWidth 和borderColor属性。

于 2011-01-14T03:03:10.057 回答
2

这是我在 Swift 中使用的:

imageView.wantsLayer = true
imageView.layer?.borderWidth = 1.0
imageView.layer?.borderColor = NSColor.red.cgColor
imageView.layer?.cornerRadius = 25.0
imageView.layer?.masksToBounds = true
于 2020-02-07T22:30:17.603 回答