Frame debugging on a device
There's this handy feature, Debug -> View Debugging -> Show View Frames, which, if turned on, draws borders around views. The sad part is that it only works on the simulator. But we can (somewhat) easily simulate its behavior.
First, we create a helper method that does the coloring:
func activateFramesDebug() {
guard debugFrames else { return }
layer.borderWidth = 1
layer.borderColor = UIColor(
hue: CGFloat(arc4random_uniform(100_000)) / 100_000,
saturation: CGFloat(arc4random_uniform(100_000)) / 100_000,
brightness: 0.5 + CGFloat(arc4random_uniform(50)) / 100,
alpha: 1.0).CGColor
}