我的搜索栏与导航栏中的行不一样?

时间:2017-12-11 01:45:50

标签: ios swift uisearchcontroller

我在哪里添加视图

let imgCart = UIImage(named: "cart")!
    let btnCart = UIButton()
    btnCart.setImage(imgCart, for: .normal)
    btnCart.setTitleColor(.white, for: .highlighted)
    btnCart.addTarget(self, action: #selector(openCategory(_:)), for: UIControlEvents.touchUpInside)

    let cartBarBtn = UIBarButtonItem(customView: btnCart)

    createSearch()

    let btnMenu = UIButton()
    let menuImage = UIImage(named: "menu")!
    btnMenu.setImage(menuImage, for: .normal)
    btnMenu.sizeToFit()
    btnMenu.setTitleColor(.white, for: .highlighted)
    btnMenu.addTarget(self, action: #selector(openCategory(_:)), for: UIControlEvents.touchUpInside)
    let imgLogo: UIImage = UIImage(named: "logo")!
    let imgViewLogo = UIImageView(image: imgLogo)

    let menuBarBtn = UIBarButtonItem(customView: btnMenu)
    let logoBarBtn = UIBarButtonItem(customView: imgViewLogo)
    navigationItem.setLeftBarButtonItems([menuBarBtn, logoBarBtn] , animated: false)

搜索栏

func createSearch(){
    self.searchController = UISearchController(searchResultsController:  nil)
    self.searchController.searchResultsUpdater = self
    self.searchController.delegate = self
    self.searchController.searchBar.delegate = self
    self.searchController.hidesNavigationBarDuringPresentation = false
    self.searchController.dimsBackgroundDuringPresentation = true
    self.searchController.searchBar.sizeToFit()
    self.navigationItem.titleView = searchController.searchBar
    self.definesPresentationContext = true

}

enter image description here

您可以查看上面的截图。导航栏中的项目不是同一行。我该如何解决?

0 个答案:

没有答案