首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SearchController in iOS13

SearchController in iOS13
EN

Stack Overflow用户
提问于 2019-10-01 05:55:29
回答 2查看 555关注 0票数 0

我正在将searchController添加到navigationItem on action中。在iOS12中,它正确地显示,但在iOS 13中,它没有显示。在调试视图层次结构时,它显示已添加搜索栏,但其高度已设置为零。找不到合适的溶液。

代码:

代码语言:javascript
复制
func setupSearchController() {

    searchController = UISearchController(searchResultsController: nil)
    searchController.searchResultsUpdater = self as UISearchResultsUpdating
    searchController.searchBar.placeholder = "Search here..."
    searchController.searchBar.delegate = self as UISearchBarDelegate
    searchController.searchBar.tintColor = .white
    searchController.searchBar.barTintColor = .white
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.obscuresBackgroundDuringPresentation = false
    searchController.searchBar.showsCancelButton = true 

    if let textfield = searchController.searchBar.value(forKey: "searchField") as? UITextField {

        textfield.textColor = UIColor.blue

        if let backgroundview = textfield.subviews.first {

            // Background color
            backgroundview.backgroundColor = UIColor.white

            // Rounded corner
            backgroundview.layer.cornerRadius = 10;
            backgroundview.clipsToBounds = true;
        }
    }

    if #available(iOS 11.0, *) {
        self.navigationItem.searchController = searchController
    } else {
        self.tblView.tableHeaderView = searchController.searchBar
    }
}

Debug中的

In Size检查器,

EN

回答 2

Stack Overflow用户

发布于 2019-10-01 06:07:23

试着设置搜索栏的框架

代码语言:javascript
复制
searchController. searchBar.frame = CGRect(x: 0, y: 0, width:view.frame.size.width, height: 50)
票数 0
EN

Stack Overflow用户

发布于 2019-10-01 17:55:59

您的代码对我来说很好:

也许你的导航栏已经倒塌了?如果导航项的hidesSearchBarWhenScrolling属性为true,则导航条可以折叠以隐藏搜索栏。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58178804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档