0

Bug搜索欄和導航欄之間的誤差

我不知道爲什麼會發生這種情況。我有一個UIViewController與UITableView我想添加一個搜索欄來查詢我的服務器使用新的UISearchController(Swift 3,Xcode 8.1)。 我已經嘗試了所有在界面生成器中添加搜索欄,將搜索欄背景設置爲UIImage,但沒有任何工作。

這是視圖控制器類準系統:

class MyViewController: UIViewController { 
    var searchController = UISearchController(searchResultsController: nil) 

    fileprivate func setupSearchController() { 
    searchController.searchResultsUpdater = self 
    searchController.dimsBackgroundDuringPresentation = false 
    searchController.searchBar.barTintColor = .myColor() 
    searchController.searchBar.tintColor = .white 
    searchController.searchBar.backgroundColor = .myColor() 
    searchController.searchBar.placeholder = "searchSomething" 
    searchController.searchBar.delegate = self 
    definesPresentationContext = true 
    tableView.tableHeaderView = searchController.searchBar 
    } 
} 

extension MyViewController: UISearchResultsUpdating, UISearchBarDelegate { 
    // delegates methods... 
} 

也許這是對我的設計模式的東西,但我真的不知道是UISearchController真的是新的,我還沒有在網上找到任何很好的例子關於它的使用。

回答

0

您可以在搜索欄周圍設置與導航相同的紅色邊框。

searchBar.layer.borderColor = (your red color).cgColor 
    searchBar.layer.borderWidth = 1