Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the Identifier of a UIView in Xcode/iOS for debugging auto layout?

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:

Identifier for UIView

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?

like image 589
Rich Apodaca Avatar asked Oct 18 '12 22:10

Rich Apodaca


People also ask

What are two properties that auto Layout constraints control on a UIView?

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.

How do I add a Layout constraint in Xcode?

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.


1 Answers

Setting accessibilityIdentifier on UIView does the trick. Tested on Xcode 6.4, iOS 8.4.

like image 178
kean Avatar answered Sep 25 '22 00:09

kean