How to enable cancel button with UISearchBar?

This method worked in iOS7. – (void)enableCancelButton:(UISearchBar *)searchBar { for (UIView *view in searchBar.subviews) { for (id subview in view.subviews) { if ( [subview isKindOfClass:[UIButton class]] ) { [subview setEnabled:YES]; NSLog(@”enableCancelButton”); return; } } } } (Also be sure to call it anywhere after [_searchBar resignFirstResponder] is used.)

Change the font size of UISearchBar

I suggest yet a different option for iOS 5.0 and up: [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont systemFontOfSize:14]]; for iOS 8 (as linked by Mike Gledhill): [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{ NSFontAttributeName: [UIFont fontWithName:@”Helvetica” size:20], }]; for iOS 9 and above: [[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setDefaultTextAttributes:@{NSFontAttributeName: [UIFont fontWithName:@”Helvetica” size:20]}]; This way you don’t need to mess with … Read more

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 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;

Light gray background in “bounce area” of a UITableView

Setting transparencies is bad for performance. What you want is the gray area above the search bar, but it should still be white beyond the end of the list. You can add a subview to your UITableView that lives above the content instead. CGRect frame = self.list.bounds; frame.origin.y = -frame.size.height; UIView* grayView = [[UIView alloc] … Read more

iOS 9 searchBar disappears from table header view when UISearchController is active

I’m not sure what exactly is the problem but I ‘fixed’ it by: self.searchController.hidesNavigationBarDuringPresentation = NO; self.definesPresentationContext = NO; My guess is that UISearchController is doing something funky when it is trying to present as a navigation bar. So, this is a hack but it at least doesn’t block the user. The search bar doesn’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)