iOS 11 customise search bar in navigation bar

I just found out how to set also the rest of them: (with some help of Brandon, thanks!) The “Cancel” text: searchController.searchBar.tintColor = .white The search icon: searchController.searchBar.setImage(UIImage(named: “my_search_icon”), for: UISearchBarIcon.search, state: .normal) The clear icon: searchController.searchBar.setImage(UIImage(named: “my_search_icon”), for: UISearchBarIcon.clear, state: .normal) The search text: UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.white] Thanks for the help @Brandon! … Read more

UISearchBar text color change in iOS 7

In iOS 7 to access Text Field you have to reiterate on level more. Change your code like this for (UIView *subView in self.searchBar.subviews) { for (UIView *secondLevelSubview in subView.subviews){ if ([secondLevelSubview isKindOfClass:[UITextField class]]) { UITextField *searchBarTextField = (UITextField *)secondLevelSubview; //set font color here searchBarTextField.textColor = [UIColor blackColor]; break; } } } Note : This … Read more

UISearchBar in navigationbar

To put searchBar into the center of navigationBar: self.navigationItem.titleView = self.searchBarTop; To put searchBar to the left/right side of navigationBar: UIBarButtonItem *searchBarItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar]; self.navigationItem.rightBarButtonItem = searchBarItem;

Cannot change search bar background color

Like @aliamcami, all the answers before did not work as I would expect, either the answer did not work for me or it works but it needs too much “dummy” code. So I share another answer wrote in Swift 4 with simplified logic: for textField in searchController.searchBar.subviews.first!.subviews where textField is UITextField { textField.subviews.first?.backgroundColor = .white … Read more

How to filter NSFetchedResultsController (CoreData) with UISearchDisplayController/UISearchBar

I actually just implemented this on one of my projects (your question and the other wrong answer hinted at what to do). I tried Sergio’s answer but had exception issues when actually running on a device. Yes you create two fetch results controllers: one for the normal display and another one for the UISearchBar’s table … Read more