UISearchBar custom corners

前端 未结 5 1610
星月不相逢
星月不相逢 2020-12-31 06:46

I\'m trying to create a search bar like this:

\"enter

But I\'m noticing that I

5条回答
  •  失恋的感觉
    2020-12-31 07:19

    I am using this code UISearchBar but you can use this code with UISearchController.

        let searchBar = UISearchBar()
                    searchBar.sizeToFit()
                    searchBar.placeholder = "Search"
                    navigationItem.titleView = searchBar
    
                    if let textfield = searchBar.value(forKey: "searchField") as? UITextField {
                        textfield.textColor = UIColor.blue
                        if let backgroundview = textfield.subviews.first {
                            // Background color
                            backgroundview.backgroundColor = UIColor.white
                            // Rounded corner
                            backgroundview.layer.cornerRadius = 14;
                            backgroundview.clipsToBounds = true;
                        }
                    }
    

提交回复
热议问题