rounded corners on NSView using NSBezierPath are drawn badly

给你一囗甜甜゛ 提交于 2019-12-05 11:38:59

You should do the following on your NSWindow instance:

[window setOpaque:NO];
[window setBackgroundColor:[NSColor clearColor]];

and draw needed shape.

And check this article.

I found a solution, by using a Sublayer.

class StyledButton: NSView {
    let roundLayer: CALayer = CALayer()

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        setup()
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setup()
    }

    func setup() {
        self.wantsLayer = true
        self.layer?.addSublayer(roundLayer)
        roundLayer.frame = self.bounds
        roundLayer.cornerRadius = 3
        roundLayer.backgroundColor = NSColor.redColor().CGColor
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!