I want background of UISearchBar to be black, but when selecting the text field, it slides up and changes the background to gray:
Default:
--
When selected:
if you want to set black colour in background of UISearchBar then try it ..
UISearchBar *searchbar=[[UISearchBar alloc]init];
searchbar.barTintColor = [UIColor blackColor];
UISearchBar has a translucent property, make sure it's set to false.
Without more information, this is my best guess as to why this is happening: your tint color is black, but it's translucent, when it's not selected it shows as black because there's no view underneath, but when it's selected, a white view moves behind it, causing the black translucent to look gray.
Try this,
[[UISearchBar appearance] setBackgroundColor:[UIColor blackColor]];
[[UISearchBar appearance] setBarTintColor:[UIColor blackColor]];
Related
Why is the navigation bar color coming so weired? Why is it white above and only a bit red at the bottom. I cannot make out if the status bar is overlapping my navigation bar or what. This is the code I used to change the color of the navigation bar background:
[navbar setBackgroundColor:[UIColor redColor]];
Solution
[navbar setBarTintColor:[UIColor redColor]];
[navbar setTranslucent:NO];
Why
The color of a UINavigationBar is set with its barTintColor property.
What you're seeing is the translucent white navigation bar above your red background. The bit at the bottom is where UINavigationBar renders a shadow below the bar view.
I think this image is sufficient to solve your problem.
Transperent imageI am working on a tab bar application.I applied the color to the tab bar like this
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:137.0/255.0f green:27.0/255.0f blue:2.0/255.0f alpha:1.0f]];
My requirement is to display the tab bar transparent like below image
After applying the below code.tab bar is not displaying transparent. but it is displaying with black color background
self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
self.tabBarController.tabBar.translucent = YES;
Give suggestions for making the default tab bar as transperent
black color background image
You can create an empty image and pass it as a backgroundImage:
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
You can use a similar approach for shadows and tint, but pay attention that a tint color is something very particular that has to deal with you whole UI.
I'm getting a weird, i have a navigation bar and a view that is right under it.
I set both of them to [UIColor BlueColor], but at run time the outcome is that the nav bar has a slit darker color then the view.
Any knows what causes this?
Thanks
Your problem is that the navigation bar is translucent, and therefore the bar color is put on top of the view's color, making it appear darker. Try making the bar not translucent.
navigationBar.translucent = NO;
You can try this one:--
navigationController.navigationBar.barTintColor = [UIColor greenColor];
or
[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
I have a UISearchBar in a modal UIViewController that has presentationStyle set to UIModalPresentationStyleFormSheet.
Setting the tint colour on the search bar is only obeyed on the iphone. The iPad still ends up using the app tint color. Any reason why this is happening?
_searchBar = [[UISearchBar alloc] init];
_searchBar.tintColor = [UIColor whiteColor];
why dont you try appearance for search bar in applicationlaunch.
[[UISearchBar appearance] setTintColor:[UIColor whiteColor]];
That didn't work for me. What worked was setting the UITextField appearance, but that's iOS7 only. You can also loop over the bar's subviews and change the UITextField's tintColor:
[[UITextField appearance] setTintColor:[UIColor blackColor]];
i need to set the UINavigationBars background color to the same value as my apps global tint color.
problem here is that now all buttons in my navigation bar are the same color as its background. i now could change all UIBarButtons text color to white but this would be totally unusable. using the UIAppearance API doesn't seem to be a better way. after setting the text color of UIBarButton items to white, f.e the back arrows of the back button in my UINavigationBar are still painted with the global tint color.
also if i change the global tint color to white i loose all the flexibility that the global tint color gives us (also my text indicator would now be white and would not be seen on a white background)
what i want:
what i get using blue as global tint color
what i get when using blue as global tint color and setting uibarbutton items text color to white (see the back button - it should be white as well)
what is the recommended way to fix this problem?
I recommend that you do this:
UINavigationBar *navigationBar = [UINavigationBar appearance];
navigationBar.tintColor = [UIColor whiteColor];
Place this code in the didFinishLaunchingWithOptions: method in the AppDelegate.
For clarification as you are obviously not very experienced with this:
barTintColor is the property that would change the bar colour. tintColor changes the colour of interactive objects (such as the UIBarButtonItems)
if ([[UINavigationBar class] respondsToSelector:#selector(appearance)]) {
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
}
Try to set UINavigationBar setTintColor in specified controller (in viewDidLoad for example).