Created
March 4, 2024 23:50
-
-
Save stephancasas/627aaab1c7f348f0fb64279569f07390 to your computer and use it in GitHub Desktop.
Quickly apply a 1-pixel debugging border to NSView instances.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSView { | |
var debugBorder: NSColor? { | |
set { | |
guard let newValue = newValue else { | |
self.layer?.borderColor = nil; | |
self.layer?.borderWidth = 0; | |
return; | |
} | |
self.wantsLayer = true; | |
self.layer?.borderColor = newValue.cgColor; | |
self.layer?.borderWidth = 1; | |
} | |
get { | |
guard let color = self.layer?.borderColor else { | |
return nil; | |
} | |
return .init(cgColor: color) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment