NSAppearance not forcing the named appearance onto my windows

I am having an issue getting NSAppearance to work as described here in the documentation.

I am using Xcode 12.5.1 in macOS Big Sur 11.5.1. In my system preferences I have my computer set to Dark Aqua all the time. However, reading the linked document I should be able to force all my windows programmatically to use Aqua, but that is not the result I am getting with this.

import AppKit

class ViewController: NSViewController {
    var progressBar: NSProgressIndicator?
    weak var timer: Timer?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        // Force the appearance for testing
        self.view.appearance = NSAppearance(named: .aqua)
        let progressFrame = NSRect(x: self.view.frame.midX - view.frame.width / 2 + 30, y: self.view.frame.midY - 10, width: self.view.frame.width - 60, height: 20)
        progressBar = NSProgressIndicator(frame: progressFrame)
        self.view.addSubview(progressBar!)
        progressBar?.isHidden = false
        progressBar?.isIndeterminate = false
        progressBar?.doubleValue = 0
        progressBar?.maxValue = 1.0
        startTimer()
    }

    func startTimer() {
        timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(updateProgress), userInfo: nil, repeats: true)
    }

    @objc func updateProgress() {
        if progressBar!.doubleValue < 1.0 {
            progressBar?.doubleValue += 0.02
        } else {
            timer?.invalidate()
            progressBar?.doubleValue = 0
            progressBar?.isHidden = true
        }
    }

}

Am I missing something?

  • putting print("Appearance = (self.view.appearance!.name)") right after setting the appearance prints "Appearance = NSAppearanceName(_rawValue: NSAppearanceNameAqua)" to the console, so I know it is setting it. Do system preferences take precedence over setting this manually in code?

  • Also, setting the view appearance to aqua in Storyboard does not change this either.

Add a Comment