清除导航栏和搜索栏之间的边界 swift 4

Erase borders between navigation bar and searchBar swift 4

我将导航栏和搜索栏都设置为自定义 UIColor(我在代码中将其称为 categoryColor)。当我这样做时,我仍然看到导航栏和搜索栏之间有一条灰色的上线。我已经将 searchBar 边框颜色设置为与其他边框颜色相同,但那条灰线仍然存在。有谁知道如何摆脱它? 这是我的代码:

override func viewWillAppear(_ animated: Bool) {

    //defining the color that will be used for all the items
    let categoryColor = UIColor(hexString: selectCategory?.categoryColorHex ?? UIColor.randomFlat.hexValue())

    //changing navigation bar tint color
    navigationController?.navigationBar.barTintColor = categoryColor

    //changing searchbar tint color
    searchBar.barTintColor = categoryColor


    //change searchBar border's color 
    searchBar.layer.borderColor = categoryColor?.cgColor
    searchBar.layer.borderWidth = 3


    //changing title that appears at the top, after list is loaded
    title = selectCategory?.listName ?? "Todoey"
}

这是我在 运行 模拟时看到的图片:

使用导航控制器实现搜索栏的更好方法是在 navigationController 中使用 searchController 所以 searchController 将具有与 navigationController 相同的背景。这是一个很棒的教程:https://m.youtube.com/watch?v=h7caxpp3Xps

编辑: 此外,如果您已经实现了搜索功能,您也可以使用 searchController 来实现。只需为负责处理委托方法

的 class 设置 navigationController.searchConroller.searchBar.delegate