don't scold me for dumb questions, but I need your help, how much I googled - I could not find anything. I don't understand how to change the background of the main SafariExtensionViewController to the rgb I want?
Asked
Active
Viewed 212 times
0
-
I started looking into safari app extension development, there is a SafariExtensionViewController where there is a Custom View and it has a NSView class, I need to somehow change the background of this thing! – iFlyZed Apr 19 '22 at 15:45
-
It didn't work. – iFlyZed Apr 19 '22 at 16:16
1 Answers
0
It is elementary, just make sure you turn wantsLayer
on.
For example:
override func viewDidLoad() {
view.wantsLayer = true
view.layer?.backgroundColor = .black
}
If you are planning to change the color in a NSView inside updateLayer()
you'll need to turn wantsUpdateLayer
on as well.
class MyView: NSView {
override var wantsUpdateLayer: Bool { true }
override func updateLayer() {
layer?.backgroundColor = NSColor(named: "CustomControlColor")?.cgColor
}
}
Alternatively you could go without layers like this:
class MyView: NSView {
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
NSColor(named: "CustomControlColor")?.setFill()
dirtyRect.fill()
}
}

Paul B
- 3,989
- 33
- 46