我正在开发一个 Mac Cocoa 应用程序。我有一组图像可以用于明暗模式。
我按照这里的说明进行操作:https ://developer.apple.com/documentation/uikit/uiimage/providing_images_for_different_appearances
在viewWillLayout()
中,我为这样的视图设置了图像:
nsImgaeView.image = NSImage(named: "Image") // Does not change after toggling light/dark mode
但NSImage(named: "Image")
在我在“系统偏好设置”中切换亮/暗模式后,它根本不会改变它的外观。
我确信代码被调用是因为:
nsImgaeView.image = NSImage(named: "Another_Image") // Changes to another image after toggling
重新启动应用程序确实会改变它的外观。我猜是因为系统在初始加载后缓存了图像?