iOS 14: Changes in UISearchBar
Curious how to handle the search bar of your mobile application after updating a device to iOS 14? This tutorial is for you.
The last time I wrote about the UISearchBar, 13 was the latest version of the iOS system.
iOS13 brought many changes in this view. Back then, I was showing you how to deal with them. Right now, with iOS 14, another change happened.
Although changes are minor this time around, you, as a mobile developer, should be aware of them. Let’s check out, what’s going on with UISearchBar and latest Apple mobile system!
UISearchBar in iOS14: What you should pay attention to
If you use a UISearchBar without any custom changes, there should be no problems. But if you do otherwise, you should check your app before its release. There are not so many changes when compared to iOS 13, so in most cases the transition to the latest OS should be easy.
But in my case wasn’t because of using dark mode in iOS.
UISearchBar in iOS14: Light and dark modes
As you propably know, using the dark and light modes in iOS can be tricky - especially when you forget to implement the colors used by an app.
In iOS 14, something changed with the color of the text you type in the Search Bar. In its previous versions, the font colors adjusted to tintColor. Or you could set it with the textFielddelegate:
searchBar.textField?.textColor = .white
But right now if you use UISearchBar with a dark background, that’s not enough. You should directly call UITextField inside your search bar. You can do it like this:
let textFieldInsideSearchBar = searchBar.value(forKey: "searchField") as? UITextField
textFieldInsideSearchBar?.textColor = .white
Wrapping up: UISearchBar and iOS 14 transition
With this change you can easily set the color of typed text. But remember: if your app is adjusted to the global dark/light theme, you should also implement the font color. This can be done with a special check or by using system colors provided by Apple. For example .systemFill or .label.
That’s all, I hope this little hack will help you with using UISearchBar in the latest iOS version.