本文介绍了UISearchBar的set_cancelButtonText:禁止使用ivar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以前在iOS 12中允许使用相同的代码,但是现在当我尝试在iOS 13上运行相同的代码时,它崩溃并给我同样的错误:
Previously in iOS 12 the same code was allowed, but now when i try to run the same code on iOS 13 it crashes giving me the same error:
与以下代码行相关:
searchController.searchBar.setValue("Cancel".localized, forKey:"_cancelButtonText")
现在,我知道现在禁止访问setValue,但是如何克服此崩溃并更改取消"按钮的标题,因为搜索栏中不包含任何属性.
Now i know the access of setValue is now prohibited but how is it possible to overcome this crash and change the title of cancel button, since there is no property included in the searchbar.
推荐答案
您可以使用 UIAppearance
:
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).title = "Whatever"
这篇关于UISearchBar的set_cancelButtonText:禁止使用ivar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!