Search Controller in navigation item show black bar

雨燕双飞 提交于 2021-02-08 03:01:46

问题


Hi I have setup search controller using

private func setupSearchbar() {
        searchController = UISearchController(searchResultsController: nil)
        searchController.searchResultsUpdater = self
        searchController.obscuresBackgroundDuringPresentation = false
        searchController.searchBar.placeholder = "Search Contacts"

        self.navigationItem.searchController = searchController
        self.definesPresentationContext = true

    }

Everything was working fine until I add this code

    UINavigationBar.appearance().isOpaque = true
    UINavigationBar.appearance().isTranslucent = false
    UINavigationBar.appearance().barTintColor = UIColor(named: "PrimaryDark")
    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.font:Constants.AppTheme.Fonts.font(type: .FONT_BOLD, size: 22) ,NSAttributedString.Key.foregroundColor:UIColor.white]

    UINavigationBar.appearance().largeTitleTextAttributes   = [NSAttributedString.Key.font:Constants.AppTheme.Fonts.font(type: .FONT_BOLD, size: 34) ,NSAttributedString.Key.foregroundColor:UIColor.white]

Now When I tap on search bar big bottom black bar appears

How to fix this ?

View Debugging


回答1:


Okay So I am able to fix this issue. I am sharing this so this might helpful to other facing the same issue.

to fix this issue. In view will appear method I have set self.extendedLayoutIncludesOpaqueBars to true

 override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.extendedLayoutIncludesOpaqueBars = true

    }

Hope it helps to someone :)

Here is output




回答2:


Remove this

UINavigationBar.appearance().isOpaque = true

UINavigationBar.appearance().isTranslucent = false


来源:https://stackoverflow.com/questions/56250292/search-controller-in-navigation-item-show-black-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!