2

I have an UISearchBar, with search style "minimal", and I want to change the text color and to have a white border with 1px width. I'm trying with tintcolor but I don't get nothing

Thank you.

Tulon
  • 4,011
  • 6
  • 36
  • 56
Juanjo
  • 929
  • 1
  • 15
  • 29
  • 4
    You can try with this post: http://stackoverflow.com/questions/19048766/uisearchbar-text-color-change-in-ios-7 – nmh May 27 '14 at 09:47

1 Answers1

5

To change the text color of the UISearchBar, use this snippet

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor yourColor]];

For the white border, try this out

for (id object in [[[yourSearchBar subviews] objectAtIndex:0] subviews])
{
    if ([object isKindOfClass:[UITextField class]])
    {
        UITextField *textFieldObject = (UITextField *)object;

        textFieldObject.textColor = [UIColor redColor];
        textFieldObject.layer.borderColor = [[UIColor whiteColor] CGColor];
        textFieldObject.layer.borderWidth = 1.0;
        break;
    }
}

Hope this helps!

Edit

You can add the first line for the search bar color anywhere in your app. Also, I have added one line for the textColor in the loop, check that out.

aksh1t
  • 5,410
  • 1
  • 37
  • 55