搜索栏和导航栏之间的误差

问题描述:

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真的是新的,我还没有在网上找到任何很好的例子关于它的使用。

您可以在搜索栏周围设置与导航相同的红色边框。

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