Is there anyway to create a NSButton with rounded corners and background color without subclassing it. I have this code and it does not do anything.
let directionsButton = NSButton(frame: NSRect(x: 0, y: 0, width: 100, height: 60))
directionsButton.title = "Click Me!"
directionsButton.layer?.cornerRadius = 10
directionsButton.layer?.masksToBounds = true
directionsButton.layer?.backgroundColor = NSColor.blue.cgColor
CodePudding user response:
To enable the CoreAnimation layer you have to insert this line before using it
directionsButton.wantsLayer = true
Edit: To be able to change the color you have to draw a borderless button. Add
directionsButton.isBordered = false