本文介绍了在iOS8中使用UISearchBar启用取消按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以启用UISearchBar的取消按钮?现在每当我呼叫resignFirst响应者时,取消按钮被禁用。只有当我再次点按搜索栏时,才会启用取消。有没有办法停止取消取消按钮?

Is there any method to enable 'Cancel' button of UISearchBar? Now whenever I call resignFirst responder, cancel button gets disabled. Only when I tap over the search bar again, cancel gets enabled. Is there anyway to stop disabling the cancel button?

推荐答案

这是适用于iOS 8和Swift的解决方案。

Here's a working solution for iOS 8 and Swift.

func enableCancleButton (searchBar : UISearchBar) {
    for view1 in searchBar.subviews {
        for view2 in view1.subviews {
            if view2.isKindOfClass(UIButton) {
                var button = view2 as! UIButton
                button.enabled = true
                button.userInteractionEnabled = true
            }
        }
    }
}

这篇关于在iOS8中使用UISearchBar启用取消按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:04