UIKit comes with an on-device view debugging tool. It has been around a while, but is restricted to Apple engineers, and only accessible via private APIs. In iOS 11, Apple restricted it even further, after many people started using it externally, and various articles were posted on how to enable it.

Below is a link to a code snippet that is compatible with both iOS 10 and 11.

Warning: Do not ship this code in the app store, as it is full of private APIs. Apple may change these APIs later in the future, and it may stop working.

View code snippet