Reputation: 530
I'm setting up my search bar like so...
self.searchBar.placeholder = "Search Plants"
searchBar.layer.cornerRadius = 5
searchBar.clipsToBounds = true
searchBar.barTintColor = UIColor(red:255/255, green:127/255, blue:0, alpha:1)
if let textField = self.searchBar.subviews.first?.subviews.compactMap({ $0 as? UITextField }).first {
textField.subviews.first?.isHidden = true
textField.layer.backgroundColor = UIColor.white.cgColor
textField.layer.cornerRadius = 10
textField.layer.masksToBounds = true
}
Now when I run the project in an iPhone 7, it looks properly like so...
But when I run it in an iPhone XR, it looks like so...
What could be the reason for this...?
Upvotes: 1
Views: 81
Reputation: 20234
The searchBar.searchTextField
by default has a slightly opaque background color and so to prevent bleeding of the tintColor
, we will need to explicitly set the color.
searchBar.searchTextField.backgroundColor = .white
Upvotes: 2