Debug Colors

Debug all the views!!!

before: before after: after

Usage:

override func viewDidAppear(animated: Bool) {
  super.viewDidAppear(animated)
  debugColors()
}
func layoutSubviews() {
  super.layoutSubviews()
  debugColors()
}

Implementation:

extension UIView {
  func debugColors() {
    func randomColor() -> UIColor {
      func randomCGFloat() -> CGFloat {
        return CGFloat(arc4random()) / CGFloat(UInt32.max)
      }
      return UIColor(
        red: randomCGFloat(),
        green: randomCGFloat(),
        blue: randomCGFloat(),
        alpha: 0.7)
    }
    
    for eachSubview in subviews {
      eachSubview.backgroundColor = randomColor()
      eachSubview.debugColors()
    }
  }
}

extension UIViewController {
  func debugColors() {
    view.debugColors()
  }
}