I’ve been trying to tame the AutoLayout beast recently, and wanted to be able to see where my various views where ending up. I started to write a NSView subclass that dumped out a printable grid in the
drawRect: method when I stumbled across a neat technique that works out of the box.
Using the following command, I can get all the
NSView objects to draw a border around themselves in a different colour:
defaults write com.logdiver.LogDiver NSShowAllViews YES
Note that in the example above, the setting applies to my application that has a bundle identifier of
The result of this is a UI that looks something like:
I forgot to mention there is another very useful flag:
defaults write com.logdiver.LogDiver NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints YES
This will render problematic constraints and allow you to click on them to dump the constraint settings to the console. For example, in the following example I have set two height constraints (one is 22 and the other is 27) on the
NSTextField for the Name field.
When I click on the orange constraint arrow, the following gets emitted to the console:
2014-03-25 08:34:08.563 LogDiver[85236:303] Clicked on overlapping visualized constraints: ( "<NSLayoutConstraint:0x600000288d90 V:[nameTF(22)] (Names: nameTF:0x6180001887b0 )> (Actual Distance - pixels):44", "<NSLayoutConstraint:0x600000289100 V:[nameTF(27)] (Names: nameTF:0x6180001887b0 )> (Actual Distance - pixels):44" )