UISearchBar最小风格具有透明背景

Chr*_*ris 8 transparent uisearchbar uisearchcontroller

UISearchBar添加到了顶部UITableView.

        // init search bar
    self.resultSearchController = ({
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = self
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
        controller.searchBar.tintColor = Config.grayColor()
        controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal

        self.tableView.tableHeaderView = controller.searchBar

        // set content offset for table view in order
        // that the searchbar is hidden at the beginning
        self.tableView.contentOffset = CGPoint(x: 0, y: controller.searchBar.frame.size.height)

        return controller
    })()
Run Code Online (Sandbox Code Playgroud)

这基本上看起来像预期:

在此输入图像描述

但是当我进入搜索文本域并向下滚动表视图时,它看起来很奇怪.搜索控制器的背景是透明的.

在此输入图像描述

我试着设置barTintColorbackgroundColor,但没有任何效果.

小智 2

将 searchBar 的背景颜色设置为白色

searchBar.backgroundColor = UIColor.white