0

I'm trying to customize my search bar however I'm getting this white color obscuring the background color of my interest. This seems to be linked to my navigation barstyle as black. However, when I choose default, the white is replaced with a black one instead. Can someone help me with this? Thank you in advance! ps. im writing this in obj-c

enter image description here

BeHappy
  • 3,705
  • 5
  • 18
  • 59
GChin
  • 1
  • 1

2 Answers2

0

So I found this solution from here and it works on removing the 2 subviews

iOS 11 customise search bar in navigation bar

GChin
  • 1
  • 1
0

I knew it's already too late, but I searched a lot to fix a similar issue. So I am adding the solution which worked for me. My issue was a slightly different one compared to this one. In my case, if I added bar tint color to white, in iOS 13+ it appears very nice but in iOS 12 _UISearchBarSearchFieldBackgroundView appears like the screenshot in the question. Hence I end up on this page while searching for my problem others may reach here as well.

The white color is actually the tint color of the UISearchBar. For iOS 12 I used a slightly different color and I noticed that it's affecting the cancel button next to it as well. So I have added code to use the original color for the cancel button.

if #available(iOS 13.0, *){
        customSearchBar.tintColor = .white
    }else{
        customSearchBar.tintColor = UIColor(red: 0.46, green: 0.46, blue: 0.5, alpha: 0.12) // the color found on visual debugger
        UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(
            [NSAttributedString.Key.foregroundColor : UIColor.white],for: .normal)
    }

Here you can see that I am using a hardcode value to set the tint color. I got this color using a visual debugger while running the code in an iOS 13+ device.

You can see the appearance is identical for iOS 12 and ios 13+

enter image description here

Maneesh M
  • 193
  • 1
  • 10