Styling the cancel button in a UISearchBar

前端 未结 21 1377
-上瘾入骨i
-上瘾入骨i 2020-12-02 09:13

I have a UISearchBar that has a cancel button (it\'s displayed using -(void)setShowsCancelButton:animated). I\'ve changed the tintColor of the sear

21条回答
  •  攒了一身酷
    2020-12-02 10:06

    For iOS 11 and Swift 4. Create a subclass of UISearchController. Override method:

    override func viewDidLayoutSubviews() {
            super.viewDidLayoutSubviews()
            print("layout")
            if let btn = searchBar.subviews[0].subviews[2] as? UIButton {
                btn.frame = CGRect(x: 306, y: 20, width: 53, height: 30)
            }
    }
    

提交回复
热议问题