簡體   English   中英

導航項中的搜索控制器顯示黑條

[英]Search Controller in navigation item show black bar

嗨我已經設置了搜索控制器

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

    }

在我添加此代碼之前,一切正常

    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]

現在,當我點擊搜索欄時,會出現大底黑條

如何解決這個問題?

查看調試

在此輸入圖像描述

在此輸入圖像描述

刪除它

UINavigationBar.appearance().isOpaque = true

UINavigationBar.appearance().isTranslucent = false

好的所以我能夠解決這個問題。 我正在分享這個,所以這可能對面臨同樣問題的其他人有所幫助。

解決這個問題。 在視圖中將出現我將self.extendedLayoutIncludesOpaqueBars設置為true

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

    }

希望它對某人有幫助:)

這是輸出

在此輸入圖像描述

暫無
暫無

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

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