How to override the cancel button in the UISearchBar

后端 未结 3 2020
难免孤独
难免孤独 2021-01-20 04:32

I am currently using the following method to stop the cancel button item from showing up in the search bar. I have a custom UIButton that I would like to use in

相关标签:
3条回答
  • 2021-01-20 04:42

    Swift 4.2, 4.0+ of Rajneesh071 answer

    func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
        searchBar.setShowsCancelButton(false, animated: true)
    }
    
    0 讨论(0)
  • 2021-01-20 04:53

    You can hide your cancel button using this

    - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
    {
        [searchBar setShowsCancelButton:NO animated:YES];
    }
    
    0 讨论(0)
  • 2021-01-20 05:00
    for (UIView *possibleButton in searchBar.subviews)
    {  
        if ([possibleButton isKindOfClass:[UIButton class]])  
        {  
            UIButton *cancelButton = (UIButton*)possibleButton;  
            cancelButton.enabled = YES;  
            break;
        }    
    }
    

    one go through this link UISearchBar disable auto disable of cancel button

    0 讨论(0)
提交回复
热议问题