UISearchBar out of screen bounds when navigation bar translucent = false

不打扰是莪最后的温柔 提交于 2019-12-06 07:15:47

问题


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:


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

extendedLayoutIncludesOpaqueBars = true;


来源:https://stackoverflow.com/questions/29453228/uisearchbar-out-of-screen-bounds-when-navigation-bar-translucent-false

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!