F Severgnini
F Severgnini

Reputation: 35

Erase borders between navigation bar and searchBar swift 4

I am setting both the navigation bar and the search bar to a custom UIColor (which I call categoryColor in my code). When I do that, I still see an upper grayish line between nav bar and search bar. I have already set the searchBar border color to be the same as the others, but that gray line still exists. Does anyone know how to get rid of it? Here is my code:

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"
}

Here is a picture of what I see when I run the simulation: enter image description here

Upvotes: 1

Views: 110

Answers (1)

Roman Esin
Roman Esin

Reputation: 412

The better way for implementing search bar with nav controller would be to use searchController inside a navigationController so the searchController will have the same background as navigationController. Here’s a great tutorial about that: https://m.youtube.com/watch?v=h7caxpp3Xps

Edit: Also if you already implemented search capabilities you can do that with searchController too. Just set navigationController.searchConroller.searchBar.delegate for class that’s responsible for handling delegate methods

Upvotes: 1

Related Questions