【问题标题】:iOS 11: Add other nav items next to a search bar embedded in navigation item title viewiOS 11:在嵌入导航项标题视图的搜索栏旁边添加其他导航项
【发布时间】:2017-11-05 05:06:29
【问题描述】:

在 iOS 11 中,我们现在使用

self.navigationItem.searchController = self.searchController

在导航项标题视图中嵌入搜索栏。但是,这会将其他导航项推到搜索栏上方,如下所示:

不使用自定义容器或回到设置搜索栏的旧方式,有什么方法可以让其他导航项与 iOS 11 中的搜索栏保持在同一级别?像这样:

【问题讨论】:

    标签: ios swift uinavigationbar swift4 ios11


    【解决方案1】:

    您可以尝试通过更改取消按钮来实现此目的:

    let searchController = UISearchController(searchResultsController: nil)
    searchController.searchBar.showsCancelButton = true
    if let view = searchController.searchBar.subviews.first {
        for subview in view.subviews {
            if let myButton = subview as? UIButton {
                // setup button
                myButton.setTitle("", for: .normal)
                let image = UIImage(named: "myImage")
                myButton.setBackgroundImage(image, for: .normal)
            }
        }
    }
    navigationItem.searchController = searchController
    

    【讨论】:

      猜你喜欢
      • 2021-01-26
      • 1970-01-01
      • 2018-03-12
      • 2018-01-03
      • 2017-02-21
      • 1970-01-01
      • 2018-04-18
      • 2018-04-14
      • 1970-01-01
      相关资源
      最近更新 更多