簡體   English   中英

iOS 11:在導航項標題視圖中嵌入的搜索欄旁邊添加其他導航項

[英]iOS 11: Add other nav items next to a search bar embedded in navigation item title view

在iOS 11中,我們現在使用

self.navigationItem.searchController = self.searchController

在導航項目標題視圖中嵌入搜索欄。 但是,這會將其他導航項推送到搜索欄上方,如下所示:

在此輸入圖像描述

如果不使用自定義容器或回到設置搜索欄的舊方法,我們是否可以將其他導航項目保持在與iOS 11中的搜索欄相同的級別? 像這樣:

在此輸入圖像描述

您可以嘗試通過更改取消按鈕來實現此目的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM