UISearchBar out of screen bounds when navigation b

2019-04-11 05:48发布

I try add UISearchBarController to tableView, but when i set UINavigationBar.appearance().translucent = false then UISearchBar hide out of screen

in TableViewController

var resultSearchC: UISearchController = UISearchController()

override func viewDidLoad() {
    super.viewDidLoad()

    self.resultSearchC = ({
        let c = UISearchController(searchResultsController: nil)
        c.searchResultsUpdater = self

        c.searchBar.translucent = true

        c.searchBar.barTintColor =  .redColor()
        c.searchBar.sizeToFit()

        self.tableView.tableHeaderView = c.searchBar

        return c
    })()

    // self.edgesForExtendedLayout = .None

    self.tableView.reloadData()
}

AppDelegate:

let navBarAppearance = UINavigationBar.appearance()

    navBarAppearance.barStyle = .Black
    navBarAppearance.translucent = false

1条回答
\"骚年 ilove
2楼-- · 2019-04-11 06:42

You need to set extendedLayoutIncludesOpaqueBars to true in viewDidLoad().

extendedLayoutIncludesOpaqueBars = true;
查看更多
登录 后发表回答