Question: I've implemented a Search Bar and I want to change color of Search Bar. How can I do that?

I've tried with: 

```
self.mySearchBar.backgroundColor = [UIColor redColor];

```

but with no success.

**UPDATE (Solved):**

I had to remove the default background color before I defined background color with the following code.

```
for (UIView *subview in mySearchBar.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
        [subview removeFromSuperview];
        break;
    }
} 

```

... so code would be next:

```
  for (UIView *subview in mySearchBar.subviews) {
      if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
          [subview removeFromSuperview];
          break;
      }
  } 

  self.mySearchBar.backgroundColor = [UIColor redColor];

```

Answer: 
```
self.mySearchBar.backgroundColor = [UIColor redColor]; 

```

won't do anything,

but

```
self.mySearchBar.tintColor = [UIColor redColor]; 

```

will!
If you have issues with top and bottom lines try to remove the UISearchBarBackground:

```
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 50)];

for (UIView *subview in self.searchBar.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
        [subview removeFromSuperview];
        break;
    }
    for (UIView *subsubview in subview.subviews) {
        if ([subsubview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
            [subsubview removeFromSuperview];
            break;
        }
    }
}

self.searchBar.barTintColor = [UIColor redColor];
self.searchBar.backgroundColor = [UIColor redColor];

```