Custom clear button in UISearchBar text field

前端 未结 6 958
南笙
南笙 2020-12-06 19:12

I tried:

UITextField *searchtextfield = [searchBar.subviews objectAtIndex:1];
    UIButton *cButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cButt         


        
6条回答
  •  天涯浪人
    2020-12-06 19:54

    Swift 4.2, 4.1+ of malex answer,

    UISearchBar.appearance().setImage(UIImage(named: "image1"), for: .clear, state: .normal)
    UISearchBar.appearance().setImage(UIImage(named: "image2"), for: .clear, state: .highlighted)
    

    I also answered this here to set clear button tintColor along with results button customization.

提交回复
热议问题