How to change textColor of Cancel button of UISearchBar in iOS7?

I found answers for my own questions. Here is code , add in AppDelegate if you want to change all cancel button. [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor redColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, nil] forState:UIControlStateNormal]; Swift: let attributes = [NSForegroundColorAttributeName : UIColor.red] UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(attributes, for: .normal)

UISearchDisplayController with no results tableView?

here is a little trick that i just figured out and also you have to return 0 results while editing searchstring – (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { savedSearchTerm = searchString; [controller.searchResultsTableView setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.8]]; [controller.searchResultsTableView setRowHeight:800]; [controller.searchResultsTableView setScrollEnabled:NO]; return NO; } – (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView { // undo the changes above to prevent artefacts … Read more

Changing cursor color on UISearchBar without changing tintColor

Set your tint color to the color you want the cancel button to be and then use the UIAppearance Protocol to change the tint color on the text field to be the color you wish the cursor to be. Ex: [self.searchBar setTintColor:[UIColor whiteColor]]; [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor:[UIColor darkGrayColor]];

UISearchBar cancel button color?

I used some thing like this and worked with me: [[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor blackColor]]; it changed the cancel button color to black. Update for iOS 9.0, the method appearanceWhenContainedIn is deprecated, use appearanceWhenContainedInInstancesOfClasses instead: [[UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTintColor:[UIColor blackColor]]; And in Swift 3: UIBarButtonItem.appearance(whenContainedInInstancesOf:[UISearchBar.self]).tintColor = UIColor.black

UISearchBar x button pressed

I don’t think there’s an easy way to hook into the X button. However, you can hook into its direct consequence: cleared text. Try this: func searchBar(searchBar: UISearchBar, textDidChange searchText: String) { if searchText == “” { print(“UISearchBar.text cleared!”) } } The side effect is this also gets called when you manually clear your text.

UISearchbar keyboard search button Action

Add UISearchBarDelegate in .h Also set SearchBar’s object delegate to self. Add this to the UISearchBarDelegate’s method: – (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [searchBar resignFirstResponder]; // Do the search… } Swift func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { searchBar.resignFirstResponder() }