Skip to content

Instantly share code, notes, and snippets.

@daehn
Last active January 31, 2023 11:52
Show Gist options
  • Select an option

  • Save daehn/261cf644cde5d1ee095fafe7f9b66c56 to your computer and use it in GitHub Desktop.

Select an option

Save daehn/261cf644cde5d1ee095fafe7f9b66c56 to your computer and use it in GitHub Desktop.
UIView debugging helper
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