I am working on an app which displays search bar. Problem is that navigation view is black and I am trying to custom that bar a bit. This is my code:
if (@available(iOS 11.0, *)) {
self.viewController.navigationItem.searchController = self.searchController;
self.viewController.navigationItem.hidesSearchBarWhenScrolling = false;
self.searchController.searchBar.tintColor = [UIColor blackColor];
self.viewController.navigationItem.searchController.
searchBar.backgroundColor = [UIColor lightGrayColor];
// placeholder text
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[self.searchController.searchBar class]]] setAttributedPlaceholder:
[[NSAttributedString alloc] initWithString:@"Search"
attributes:@{NSForegroundColorAttributeName: [UIColor grayColor]}]];
// search text
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[self.searchController.searchBar class]]] setDefaultTextAttributes:
@{NSForegroundColorAttributeName: [UIColor blackColor]}];
// search bar background color
UITextField *textField = [self.searchController.searchBar valueForKey:@"searchField"];
UIView *backgroundView = textField.subviews.firstObject;
backgroundView.backgroundColor = UIColor.whiteColor;
backgroundView.layer.cornerRadius = 10;
backgroundView.clipsToBounds = YES;
[UISearchBar.self]).attributedPlaceholder = NSAttributedString(string: "placeholder", attributes: [NSAttributedStringKey.foregroundColor: UIColor.white])
} else {
self.tableView.tableHeaderView = self.searchController.searchBar;
}So I am trying to have search bar with gray color background white and text in black(placeholder and search text). My problem is that when I set placeholder text to use attributed string I don't see anymore neither the magnifying glass nor the empty button. How could I get them back ?
Also I see the search bar not centered.
How could I center it? I am coding this for iOS 11 device
I have tried
barTintColor and it does not workThnaks and regards