3
我嘗試添加UISearchBarController到的tableView,但是當我設置UINavigationBar.appearance()。半透明= false,那麼隱藏的UISearchBar出屏幕的的UISearchBar出屏幕邊界時導航欄半透明=假
在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
你必須把它寫在你的UINavigationController子類,而不是在你的活動視圖控制器 – 2016-03-29 19:07:23
感謝@ArtyomDevyatov – Andrespch 2016-11-28 10:38:11
@ArtyomDevyatov @Andrespch對於iOS10和iOS11,沒有需要繼承UINavigationController的,你可以做: '讓navVC = UINavigationController(rootViewController:rootVC) navVC.extendedLayoutIncludesOpaqueBars = true' – 2017-10-03 15:18:04