Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The short answer is not really, OS X has an identifier property that can be set on a view that is used by NSLayoutConstraint to help identify views but that doesn't exist on iOS yet.</p> <p>However there is a 'work around' to implement something similar on iOS but it isn't pretty. First you have to establish a name for each view, this accomplished in the UIView category. Then you have to update the output for NSLayoutConstraint description to use the new tags.</p> <pre><code>@interface NSLayoutConstraint (Nametags) - (NSString *)asciiArtDescription; @end @interface UIView (Nametags) @property (nonatomic, strong) NSString *nametag; @end </code></pre> <p>Then provide the implementation as follows to change the output of NSLayout</p> <pre><code>#import &lt;objc/objc-runtime.h&gt; static const char nametag_key; @implementation NSLayoutConstraint (Nametags) - (NSString *)description { NSMutableString *myDescription = [NSMutableString stringWithFormat:@"%@, ", [self asciiArtDescription]]; UIView *firstView = (UIView *)[self firstItem]; if (firstView) { [myDescription appendFormat:@"First View: 0x%0x: %@, ", (int)firstView, firstView.nametag]; } UIView *secondView = (UIView *)[self secondItem]; if (secondView) { [myDescription appendFormat:@"Second View: 0x%0x: %@", (int)secondView, secondView.nametag]; } return myDescription; } @end @implementation UIView (Nametags) - (id) nametag { return objc_getAssociatedObject(self, (void *) &amp;nametag_key); } - (void)setNametag:(NSString *) theNametag { objc_setAssociatedObject(self, (void *) &amp;nametag_key, theNametag, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } @end </code></pre> <p>Then you will be able to set names on your views like so</p> <pre><code>self.view.nametag = @"MyUsefulName"; </code></pre> <p>Or define them in IB</p> <p><img src="https://i.stack.imgur.com/V4003.png" alt="nametag in IB"></p> <p>Finally when ever you dump constraints you will get the names you provided in the output.</p> <pre><code>"V:|-(202)-[UIView:0x75606f0], First View: 0x75606f0: Blue View, Second View: 0x7560bd0: (null)", "V:[UIView:0x75606f0]-(72)-|, First View: 0x7560bd0: (null), Second View: 0x75606f0: Blue View", "V:[UIView:0x7560bd0(548)], First View: 0x7560bd0: (null), " </code></pre> <p>You should only use this code in your debug builds, don't ship it in an app because it accesses the private [NSLayoutConstraint asciiArtDescription] method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload