Last active
January 31, 2023 11:52
-
-
Save daehn/261cf644cde5d1ee095fafe7f9b66c56 to your computer and use it in GitHub Desktop.
UIView debugging helper
This file contains hidden or 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
| public extension UIView { | |
| static var debugColors: [UIColor] { | |
| return [ | |
| .red, | |
| .green, | |
| .blue, | |
| .cyan, | |
| .yellow, | |
| .magenta, | |
| .orange, | |
| .purple, | |
| .brown | |
| ] | |
| } | |
| @objc func debugViews() { | |
| debug() | |
| } | |
| func debug(startIndex: Int? = nil) { | |
| var index = startIndex ?? 0 | |
| subviews.forEach { view in | |
| view.layer.borderWidth = 1 | |
| let color = UIView.debugColors[index] | |
| view.layer.borderColor = color.withAlphaComponent(0.2).cgColor | |
| view.backgroundColor = color.withAlphaComponent(0.05) | |
| index = index == UIView.debugColors.count - 1 ? 0 : index + 1 | |
| view.debug(startIndex: index) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment