Modifying the look of an NSButton with a CALayer works differently in macOS 10.12 and 10.10

612 views Asked by At

I am trying to change the look of an NSButton in my app. The button is "Square" and "Momentary Push In".

The code is:

let layer = CALayer()
toggleTimespanButton.wantsLayer = true
toggleTimespanButton.layerContentsRedrawPolicy = NSViewLayerContentsRedrawPolicy.onSetNeedsDisplay
layer.backgroundColor = NSColor.white.cgColor
layer.cornerRadius = (toggleTimespanButton.bounds.size.width)/2
layer.masksToBounds = true
layer.borderWidth = 1
layer.borderColor = appDelegate.mainColor.cgColor
toggleTimespanButton.layer = layer

The button looks fine in macOS 10.12:

enter image description here

But in macOS 10.10 the button title is not visible. Everything looks and works fine, including the button being white and the border pink etc.

But why is the button title is not visible in macOS 10.10?

I have tried to disable all the lines one by one and the text reappears only when the layer is not added to the button...

0

There are 0 answers