NSButton in Catalina has no selected state

陌路散爱 提交于 2019-11-28 00:50:24

问题


I have an NSButton set as a checkbox with the following code on Catalina (Mojave is fine):

let checkbox = NSButton(frame: NSRect(x: 0, y: 0, width: 200, height: 32))
checkbox.setButtonType(.switch)
checkbox.title = "Sustain"
checkbox.state = .off
self.view.addSubview(checkbox)

It looks fine when I load the app

But as soon as I check it, the tick mark that I expect to be there isn't there

If I load up the visual hierarchy debugger I can see it fine, I've tried putting this code straight onto a new app and it works, but in my app it's hidden, almost like something is overriding it...any help appreciated

It also happens on NSPopUpButtons....no borders :-s

Update: 14th October 2019

As mentioned in the comments, it appears it's an Xcode 11 bug, Xcode 10.3 renders the button correctly on Catalina.

Update: 10th October 2019

Weirdly, creating a subclass and setting a CIFilter shows the checkbox item, you only have to do this to one NSButton, then suddenly, all the rest work :-s

import AppKit

class Checkbox : NSButton {

init() {
  super.init(frame: .zero)
    addFilter()
}

required init?(coder: NSCoder) {
    super.init(coder: coder)
    addFilter()
}

// add random cifilter
func addFilter() {
    let colorFilter = CIFilter(name: "CIFalseColor")!
    colorFilter.setDefaults()
    colorFilter.setValue(CIColor(cgColor: NSColor.black.cgColor), forKey: "inputColor0")
    colorFilter.setValue(CIColor(cgColor: NSColor.white.cgColor), forKey: "inputColor1")
    self.contentFilters = [colorFilter]
}


}

Doing the same for the dropdown works, but it's invisible until you click it...starting to feel like a Catalina bug

来源:https://stackoverflow.com/questions/58291431/nsbutton-in-catalina-has-no-selected-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!