Created
May 18, 2015 12:10
-
-
Save IgorMuzyka/61a22339d1aff384ac0f to your computer and use it in GitHub Desktop.
Find first subview of class in the view hierarchy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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