Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change background color of UISearchBar in iOS7

How to change background color of UISearchBar in iOS7?

enter image description here

not gray, I want to change color like my uinavigationbar

if I Use this code, that's what comes out

searchBar.backgroundColor = [UIColor redColor]; 

enter image description here

That is not red color!!! This exact same situation as in background color of navigation bar.

like image 936
dev.nikolaz Avatar asked Oct 10 '13 16:10

dev.nikolaz


People also ask

How do I change the color of my UISearchBar in Swift?

Change Search Bar Default Image Color The left hand default search image in UISearchBar represents the left view of the UITextField. The Image is rendered to change it to the desired colour. @IBOutlet weak var searchBar: UISearchBar! Hope it will help you in customising the UISearchBar in your app.

How do I change the background color in Xcode?

At the top select the attributes inspector. Under the section "View" there should be a spot that says "Background". click that and choose your colour.


2 Answers

Need to use:

searchBar.barTintColor = [UIColor redColor]; 

enter image description here

All thanks!

like image 65
dev.nikolaz Avatar answered Sep 20 '22 04:09

dev.nikolaz


Set the background image to a clear image and you're good to go. This is also pre-ios 7 compatible.

searchBar.backgroundImage = [[UIImage alloc] init] searchBar.backgroundColor = [UIColor redColor]; 
like image 23
Vadoff Avatar answered Sep 20 '22 04:09

Vadoff