During a talk from WWDC 2012 (Best Practices for Mastering Auto Layout), the presenter said that you can set a UIView identifier in Xcode to aid in debugging auto layout:
This seems like a really good idea, but in Xcode 4.5.1 for my iOS project, there is no way that I can see to set the Identity of a UIView.
How can I set the Identity of a UIView in Xcode 4.5.1? If this isn't possible in iOS projects, how can I get the same functionality?
Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews. You can access the view's margins using either the layoutMargins or layoutMarginsGuide property. The layoutMargins property lets you get and set the margins as a UIEdgeInsets structure.
To create constraints select the button and click the Align icon in the auto layout menu. A popover menu will appear, check both “Horizontal in container” and “Vertically in container” options to center the button on the screen. Then click the “Add 2 Constraints” button. Run the application.
Setting accessibilityIdentifier
on UIView
does the trick. Tested on Xcode 6.4, iOS 8.4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With