Skip to content

Instantly share code, notes, and snippets.

@IgorMuzyka
Created May 18, 2015 12:10
Show Gist options
  • Save IgorMuzyka/61a22339d1aff384ac0f to your computer and use it in GitHub Desktop.
Save IgorMuzyka/61a22339d1aff384ac0f to your computer and use it in GitHub Desktop.
Find first subview of class in the view hierarchy
- (UIView *)getFirstViewOfClass:(__unsafe_unretained Class)class inView:(UIView *)view {
UIView *searchedView;
NSArray *subviews = [NSArray new];
for (UIView *subview in view.subviews) {
subviews = [subviews arrayByAddingObject:subview];
if ([subview isMemberOfClass:class]) {
searchedView = subview;
break;
}
}
if (!searchedView && subviews.count) {
for (UIView *subview in subviews) {
searchedView = [self getFirstViewOfClass:class inView:subview];
if (searchedView) {
break;
}
}
}
return searchedView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment