之前已經詢問過這個問題的各種變化,但沒有一個解決方案適用於我。我已經使tableViewHeader searchBar,這是我迄今爲止。帶邊框的自定義搜索欄
我的代碼如下所示:
override func viewDidLoad() {
super.viewDidLoad()
configureSearchBar()
self.tableView.separatorColor = UIColor(red:0.00, green:0.87, blue:0.39, alpha:1.0)
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
func configureSearchBar() {
searchController.searchBar.delegate = self
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.placeholder = "Search Companies"
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
searchController.searchBar.barTintColor = UIColor.white
//makes border for search box and gives color and rounded
//searchController.searchBar.layer.borderColor = UIColor(red:0.00, green:0.87, blue:0.39, alpha:1.0).cgColor
//searchController.searchBar.layer.borderWidth = 2.0
//searchController.searchBar.layer.cornerRadius = 15.0
}
而且我試圖建立這一點,但到目前爲止,我還沒有成功
如果我試試這個:
searchController.searchBar.layer.borderColor = UIColor(red:0.00, green:0.87, blue:0.39, alpha:1.0).cgColor
searchController.searchBar.layer.borderWidth = 1.0
searchController.searchBar.layer.cornerRadius = 15.0
searchController.searchBar.clipsToBounds = true
它最終看起來像這正是我正在尋找。
謝謝您的幫助先進
如果您發佈當前代碼,則更有可能獲得有用的回覆。 – nathan
[如何更改搜索欄(Swift)中的邊框和圖標]的可能重複](https://stackoverflow.com/questions/31413127/how-to-change-border-and-icons-in-search-bar-swift ) – arvidurs