Subview-Struktur ausgeben


Aus Macwrench

Wechseln zu: Navigation, Suche

Um die komplette Subview-Struktur im Log auszugeben, kann folgendes Snippet verwendet werden:

- (void)debugSubviewsInView:(NSObject*)view prefix:(NSString*)prefix {
	if (prefix == nil) {
		prefix = @"";
	} else {
		prefix = [prefix stringByAppendingString:@" "];
	}
	if ([view respondsToSelector:@selector(subviews)]) {
		for (NSObject *subview in [view performSelector:@selector(subviews) withObject:nil]) {
			NSLog(@"%@ %@ %@",prefix,(prefix.length == 0 ? @"-" : @"|-"),subview.class);
			if ([subview respondsToSelector:@selector(subviews)]) {
				[self debugSubviewsInView:subview prefix:prefix];
			}
		}
	}
}

Hier die Beispielausgabe eines UIAlertController:

- UIView
 |- UIView
  |- UIView
   |- _UIAlertControllerShadowedScrollView
    |- UIView
     |- UILabel
     |- UILabel
     |- UIView
    |- UIImageView
    |- UIImageView
   |- UILabel
   |- UICollectionView
    |- _UIAlertControllerCollectionViewCell
     |- UIView
      |- _UIAlertControllerActionView
       |- _UIBlendingHighlightView
        |- UIView
        |- UIView
       |- UIView
        |- UILabel
        |- UILabel
       |- UIImageView
       |- UIImageView
       |- UIView
    |- _UIAlertControllerCollectionViewCell
     |- UIView
      |- _UIAlertControllerActionView
       |- _UIBlendingHighlightView
        |- UIView
        |- UIView
       |- UIView
        |- UILabel
        |- UILabel
       |- UIImageView
       |- UIImageView
       |- UIView
    |- _UIAlertControllerCollectionViewCell
     |- UIView
      |- _UIAlertControllerActionView
       |- _UIBlendingHighlightView
        |- UIView
        |- UIView
       |- UIView
        |- UILabel
        |- UILabel
       |- UIImageView
       |- UIImageView
       |- UIView
    |- _UIAlertControllerCollectionViewCell
     |- UIView
      |- _UIAlertControllerActionView
       |- _UIBlendingHighlightView
        |- UIView
        |- UIView
       |- UIView
        |- UILabel
        |- UILabel
       |- UIImageView
       |- UIImageView
       |- UIView
    |- _UIAlertControllerBlendingSeparatorView
     |- _UIBlendingHighlightView
      |- UIView
      |- UIView
    |- _UIAlertControllerBlendingSeparatorView
     |- _UIBlendingHighlightView
      |- UIView
      |- UIView
    |- _UIAlertControllerBlendingSeparatorView
     |- _UIBlendingHighlightView
      |- UIView
      |- UIView
    |- _UIAlertControllerBlendingSeparatorView
     |- _UIBlendingHighlightView
      |- UIView
      |- UIView
    |- UIImageView
    |- UIImageView
  |- _UIAlertControllerActionView
   |- _UIBlendingHighlightView
    |- UIView
    |- UIView
   |- UIView
    |- UILabel
    |- UILabel
   |- UIImageView
   |- UIImageView
   |- UIView
Ansichten