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?