UITextField* textField = (UITextField*)[selffindSubview:@"UISearchBarTextField"resursion:YES];
NSString* buttonName = @"UINavigationButton";
UIButton* button = (UIButton*)[self findSubview:buttonName resursion:YES];
[button setEnabled:YES];
button.tintColor = [UIColor blackColor];
[button setTitle:@"取消" forState:UIControlStateNormal];
- (UIView *)findSubview:(NSString *)name resursion:(BOOL)resursion
{
Class class = NSClassFromString(name);
for (UIView *subview in self.subviews) {
if ([subview isKindOfClass:class]) {
return subview;
}
}
if (resursion) {
for (UIView *subview in self.subviews) {
UIView *tempView = [subview findSubview:name resursion:resursion];
if (tempView) {
return tempView;
}
}
}
return nil;
}
参考Facebook的UIView的类别 UIViewAdditions.h