I am using below code. It is working perfectly in IOS 6.x. building from Xcode 4.6.x . But that code is not working no more in IOS 7.x building from xcode 5.x.
My objective is to display a custom image in place of cancel button of UISearchBar when user start editing in UISearchBar.
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
[searchBar setShowsCancelButton:YES animated:YES];
UIButton *cancelButton = nil;
for(UIView *subView in searchBar.subviews){
if([subView isKindOfClass:UIButton.class]){
cancelButton = (UIButton*)subView;
}
}
[cancelButton setTintColor:[UIColor colorWithRed:167.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:1.0f]];
[cancelButton setBackgroundImage:[UIImage imageNamed:@"customKeyboardIcon.png"] forState:UIControlStateNormal];
[cancelButton setTitle:nil forState:UIControlStateNormal];
}