如何在NavigationBar Title下插入UISearchBar

时间:2016-08-24 16:10:55

标签: ios swift uinavigationbar uisearchbar

任何人都可以帮我吗?

我希望将searchBar放在navigationBar中,但是在Title下面(这样做的原因是我想要一个用于NavigationBar& SearchBar的图像)从NavigationBar中获得< = 1px阴影的问题。我已经完成了将searchBar放在NavigationItem“Title”中,但我希望它低于它。以下是我将searchBar放在NavBar中的内容:

func createSearchBar()
{
    let searchBar = UISearchBar()
    searchBar.showsCancelButton = false
    searchBar.placeholder = "Search"
    searchBar.delegate = self
    self.navigationItem.titleView = searchBar
}

1 个答案:

答案 0 :(得分:0)

您需要在导航栏中添加自定义视图,即查看中心。

也许这可以帮到你:

Can't set titleView in the center of navigation bar because back button

或创建自定义导航栏:

https://www.codeschool.com/blog/2014/11/11/ios-app-creating-custom-nav-bar/