Customize UISearchBar: Trying to get rid of the 1px black line underneath the search bar

Try this

 searchBar.layer.borderWidth = 1;

 searchBar.layer.borderColor = [[UIColor lightGrayColor] CGColor];

Why:

So, I've dug into the API's trying to figure out why this is happening. Apparently whomever wrote the UISearchBar API is rasterizing the lines onto an image and setting it as it's backgroundImage.

Solution:

I propose a simpler solution, if you want to set the backgroundColor and get rid of the hairlines:

searchBar.backgroundColor = <#... some color #>
searchBar.backgroundImage = [UIImage new];

Or if you just need a background image without the hairlines:

searchBar.backgroundImage = <#... some image #>

I have 0.5px black horizontal lines both on top and on the bottom of my UISearchBar. The only way I had so far to get rid of them is by setting its style to Minimal:

mySearchBar.searchBarStyle = UISearchBarStyleMinimal;