macos开发-NSButton设置image在某些旧系统上不显示图片

场景

  • 点击按钮nsbutton显示选中状态图片,再次点击显示撤销状态图片。

出现的问题

  • 设置按钮背景图片后,个别系统不显示按钮的图片,但可触发点击事件。

解决方法

  • 不使用onoff类型的按钮,使用switch类型的按钮即可解决。缘由未知。

     lazy var shareScreenBtn: NSButton = {
         let btn = NSButton()
         btn.wantsLayer = true
         btn.image = NSImage.init(named: AppLanguage.shared.local("E_screenshare"))
         btn.alternateImage = NSImage.init(named: AppLanguage.shared.local("E_stopSharing"))
         btn.isBordered = false
         btn.target = self
         btn.action = #selector(shareScreenBtnClick(sender:))
//        btn.setButtonType(NSButton.ButtonType.onOff)  
         btn.setButtonType(NSButton.ButtonType.switch)
         btn.isHidden = true
         return btn
     }()

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容