我知道您可以使用文本字段上的清除按钮来完成此操作,如下所示:
searchController?.searchBar.searchTextField.clearButtonMode = .whileEditing但是搜索栏上的cancel按钮有没有类似的功能呢?
searchController?.searchBar.showsCancelButton = true // this exists
searchController?.searchBar.cancelButtonMode = .whileEditing // I could not find this

谢谢!
发布于 2019-10-20 08:05:25
如果您不希望在用户实际点击搜索控制器的搜索栏之前不显示搜索栏,请不要为cancel按钮添加任何代码。默认行为是在用户激活搜索之前不显示cancel按钮。
只需删除设置或更改cancel按钮所需的所有代码。
在iOS 13中,您可以使用UISearchController的automaticallyShowsCancelButton属性,但在iOS中,它缺省为true。在Mac Catalyst下,它似乎默认使用false。
https://stackoverflow.com/questions/58468949
复制相似问题