Answer the question
In order to leave comments, you need to log in
Why can't cancelButton in searchBar have time to be renamed?
Problem:
Trying to rename the Cancel button for a UISearchBar, it gets renamed, but not on the first interaction. What's my mistake?
Details:
I'm trying to implement in UISearchBarDelegate
, namely in searchBarShouldBeginEditing
Here's how it looks:
let customCancelButton = searchBar.value(forKey: "cancelButton") as? UIButton
customCancelButton?.setTitle("Отменить", for: .normal)
searchBar.setShowsCancelButton(true, animated: true)
searchBar.showsCancelButton = true
return true
Answer the question
In order to leave comments, you need to log in
Everything turned out to be so simple ...
In order to change the name on the button and not touch the streams duringViewDidLoad()
searchBar.setValue("Отменить", forKey: "cancelButtonText")
cancelButtonText
- responsible for this button. searchBar.setShowsCancelButton(true, animated: true)
searchBar.showsCancelButton = true
DispatchQueue.main.async
{ // changed the name here}, and already below I did the button display - the problem was almost solved, but the UI did not see the size of the button the first time. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question