I want a simple push button (the one with the round corners), and to add background to it. I\'ve tried 2 things:
1 - using a round button image: this is working good, un
I made a button and succeeded. It looks like this:
Code:
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
// Drawing code here.
if let bgColor = bgColor {
self.layer?.cornerRadius = 4
self.layer?.masksToBounds = true
self.layer?.backgroundColor = bgColor.cgColor
bgColor.setFill()
NSRectFill(dirtyRect)
}
}
drawRect is replaced by draw, and CGColor is replaced by cgColor. The difference between yours and mine is the order. You called super.draw(dirtyRect)
as last, and I called it first. Maybe your button looks like this:
I hope this can solve your problem.