/
SubviewFinder.m
51 lines (38 loc) · 900 Bytes
/
SubviewFinder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// SubviewFinder.m
// Circuit Timer
//
// Created by Ian Forsyth on 11/3/13.
// Copyright (c) 2013 Ian Forsyth. All rights reserved.
//
#import "SubviewFinder.h"
@implementation UIView (SubviewHunting)
- (UIView*) huntedSubviewWithClassName:(NSString*) className
{
if([[[self class] description] isEqualToString:className])
return self;
for(UIView* subview in self.subviews)
{
UIView* huntedSubview = [subview huntedSubviewWithClassName:className];
if(huntedSubview != nil)
return huntedSubview;
}
return nil;
}
- (void) debugSubviews
{
[self debugSubviews:0];
}
- (void) debugSubviews:(NSUInteger) count
{
if(count == 0)
printf("\n\n\n");
for(int i = 0; i <= count; i++)
printf("--");
printf(" %s\n", [[self class] description].UTF8String);
for(UIView* x in self.subviews)
[x debugSubviews:(count + 1)];
if(count == 0)
printf("\n\n\n");
}
@end