gpt4 book ai didi

ios - 即使键盘关闭,也保持搜索栏取消按钮色调颜色

转载 作者:搜寻专家 更新时间:2023-11-01 05:43:36 24 4
gpt4 key购买 nike

我的导航栏中有一个带有取消按钮的搜索栏,当键盘关闭时,我的取消按钮会改变颜色并变为非事件状态,直到我再次单击它。有没有办法让我的取消按钮每次都保持相同的状态?

这是在我关闭键盘之前

enter image description here

这是在我关闭键盘之后

enter image description here

我希望我的取消按钮在键盘关闭前后保持不变。感谢您的帮助!

最佳答案

我想你做不到,我的方法是在右边做一个宽度的按钮,当用户按下搜索栏时,按钮宽度会改变,即使用户搜索并关闭键盘它仍处于事件状态,但按下时宽度为零,搜索栏结束编辑 enter image description here enter image description here然后当按下取消时,只需使其宽度为零

实现:

1-在 tabbar 的右侧添加一个按钮-用于按钮的约束:您想要的底部约束,宽度为零,您想要的高度,尾部也为零。

2-对于tab bar的约束:尾部必须为0,其他随意

3- 不要忘记使用 UISearchBarDelegate

4-in viewdidload set yoursearchbar.delegate = self

5-

 func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
//wcha.hey = hello.text!
this will fire when tuching search bar for first time
self.allview.layoutIfNeeded()
yourcancelbutton.constant = your desired width

}

6-

 @IBAction func yourcancelbutton(_ sender: Any) {

yourbutton.constant = 0
self.view.endEditing(true)
}

关于ios - 即使键盘关闭,也保持搜索栏取消按钮色调颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51344811/

24 4 0