Reputation: 445
In IOS searchBar i am able to add cancel image and remove text but one problem is when i searchBar Bar tint color clear after that my image is not show , and i have to clear color in tint bar for UI
i have to add image in searchbar cancel button
Here is my code
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
self.searchDisplayController.searchBar.showsCancelButton = YES;
UIButton *cancelButton;
UIView *topView = self.searchDisplayController.searchBar.subviews[0];
for (UIView *subView in topView.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
cancelButton = (UIButton*)subView;
}
}
if (cancelButton) {
//Set the new title of the cancel button
[cancelButton setTitle:@" " forState:UIControlStateNormal];
// [cancelButton setBackgroundColor:[UIColor redColor]];
[cancelButton setImage:[UIImage imageNamed:@"close_icon.png"] forState:UIControlStateNormal];
}
}
After Clear tint bar color
Please Give me solution ............... Is Any Hope Please Help me ........... please help , is there 5 day complete and i don't have any solution
Upvotes: 2
Views: 163
Reputation: 563
Put this method in you search bar delegates. You need not add image
(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar1
{
[searchBar setShowsCancelButton:YES animated:YES];
}
Upvotes: 0