我已经将一个 UISearchBar
添加到了一个 UITableView
的顶部。
// init search bar
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.tintColor = Config.grayColor()
controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal
self.tableView.tableHeaderView = controller.searchBar
// set content offset for table view in order
// that the searchbar is hidden at the beginning
self.tableView.contentOffset = CGPoint(x: 0, y: controller.searchBar.frame.size.height)
return controller
})()
这基本上看起来像是预期的::
但当我输入搜索文本字段并向下滚动表视图时,它看起来很奇怪。搜索控制器的背景是透明的。
我尝试过设置barTintColor
和backgroundColor
,但没有任何效果。