I have a UIView that I am loading and it has a navigation bar with a 'Done' barButton. When I leave the navigation bar the default color, everything is fine. When I make it have a black tint, the 'Done' button works fine but it does not have the pressing animation that buttons usually have. It doesn't look as thought the button is being pressed. Does anyone know why this is?
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle: NSLocalizedString(#"Done", #"")
style:UIBarButtonItemStyleDone
target:self
action:#selector(donePressed:)]
autorelease];
Thank you so much!
[UIColor blackColor] does not supply a second color for the push effect. Your best best bet is to use darkGreyColor on the navigationBar or if you really need black then you'll have to animate this yourself.
I've heard that the reason black doesn't have a second color is because there is no color darker than black.
Related
I made iOS app, in which i want my app to compatible with iOS 7
Problem which i am facing is, when i run my app on iOS 7, Background image of my UINavigationBar hides my titleview and back button
:
-(void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"top.png"] forBarMetrics:UIBarMetricsDefault];
self.title=#"Artist";
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
}
also when, i set Background image of UINavigationBar to nil it shows titleview and back button
When i run my apps prior to iOS 7 it works properly.
Please help.
Thanks in advance.
Behavior of tintColor for bars has changed on iOS 7.0, please check the image below:
You can see that
tintColor: is the color for the interactive elements within a navigation bar including button images and titles.
barTintColor is the background color of the UINavigationBar.
For your issue: you can do the below:
navigationBar.tintColor = [UIColor whiteColor];
navigationBar.barTintColor = [UIColor colorWithRed:6.0/255.0 green:12.0/255.0 blue:19.0/255.0 alpha:1.0];
The default font color is black so you are probably drawing a black font on a black background. Try the following:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], NSForegroundColorAttributeName,nil]];
check the property extend edges on the property inspector of your view this will extend the edges from the bottom of your navigation bar to the top of your screen so your background image will be at the right place
check the transition guide for ios7 if you want more info about new things in ios7
https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/TransitionGuide/index.html
following code worked for me
In viewDidLoad
self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
i'm porting now ios6 app to ios7 sdk (with Xcode 5 and mavericks) and i tried to change UIBarButtonItem color, here is what i try to do:
self.navigationController.navigationBar.tintColor
- make changes color for bar but not for items
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor greenColor]];
- doesn't work, same wrong color
self.navigationItem.rightBarButtonItem.tintColor = [UIColor greenColor];
self.navigationItem.leftBarButtonItem.tintColor = [UIColor greenColor];
- doesn't work, same wrong color
UIBarButtonItem *close = [[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(#"Close",#"")
style:UIBarButtonItemStyleDone target:self
action:#selector(closeAddressBook:)];
close.tintColor = [UIColor greenColor];
- doesn't work, same wrong color
for self.filterSegment.tintColor = [UIColor greenColor] where UISegmentedControl *filterSegment;
i see unselected segment with correct color, but selected segment is a same wrong color.
any ideas?
Figured out what needs to be done, thanks to WWDC 2013 - Customizing Your App’s Appearance for iOS 7.
self.navigationController.navigationBar.tintColor = [UIColor redColor];
This will filter down into the other views in your app, so place on initial screen, and if you push to the next screen you will see that the back button is also red.
To change the navigation bar colour use
self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
If you are making your app work for devices less than iOS7, you should check it responds to the selector
if([self.navigationController.navigationBar respondsToSelector:#selector(barTintColor)]) {
}
For iOS7 this code works for me when I wish to change the colour of an individual UIBarButtonItem:
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Title" style:UIBarButtonItemStyleBordered target:self action:nil];
[barButtonItem setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItems = #[barButtonItem];
It might be a good idea to set the tintColor property on your app's UIWindow instance instead. If you've got a standard 'accent' colour you're using throughout your app, this will tint every control in the app with that colour.
1- In iOS 7, the tintColor property is no longer used for setting the color of the bar. Instead, use the barTintColor property to change the background color.You can insert the below code in the didFinishLaunchingWithOptions: of AppDelegate.m.
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
2- In iOS 7, all bar buttons are borderless. The back button is now a chevron plus the title of the previous screen (or just displays ‘Back’ as the button title if the title of the previous screen is nil). To tint the back button, you can alter the tintColor property, which provides a quick and simple way to skin your app with a custom color. Below is a sample code snippet:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
self.navigationController.navigationBar.tintColor = [UIColor redColor];
This is the way to set the color for the backbutton.
Just a note for ppl who developed the app using IOS 6, we used the above code to set the Nav Bar Color, so by mistake if you did not remove the previous setting you will not see the change to the back button.
I finally figured out the way to solve this problem.
After setting the button, you need to wait 5-7 ms (in case of iPhone 5s).
UIBarButtonItem *button=[[UIBarButtonItem alloc]...
self.navigationItem.rightBarButtonItem=button;
[button performSelector:#selector(setTintColor:) withObject:[UIColor blueColor] afterDelay:0.1];
You shouldn't set the color before setting rightBarButtonItem. It should work for both iOS 6 & 7.
I have a UINavigationBar, and the colour of it is purple. I have added a uibarbutton of the left of it. It too is purple, But what i want it to look is black.
1.) I only need the navigationbar to remain purple, everything else uibarbutton, navigation back button (when we go from one view to another we get a arrow shaped back button) should be black.
I used the interface builder to change the colour of the uibarbutton (setTint), but when i ran it on my iOS 4.3 device it still appears as purple.
I tried cleaning, building and re-installing the app nothing hapence.
Just set it up like this
// Loads the view
-(void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationItem.leftBarButtonItem = [UIBarButtonItem* settings = [[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStylePlain target:self action:#selector(settingsButtonEvent:)]];
[self.navigationItem.leftBarButtonItem setTintColor:[UIColor redColor]];
// some more code for your view
}
You can't set a different tintColor for both objects, but you can set an image as the button background.
I hope it helps you!
I'm adding the items programatically, but MKUserTrackingBarButtonItem doesn't seem to offer any way to style it to fit in with a BlackTranslucent UIToolBar...
MKUserTrackingBarButtonItem is a subclass of UIBarButtonItem which has a tintColor property. You can use this to make your button black.
MKUserTrackingBarButtonItem *userTrackingBarButtonItem =
[[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlack];
[userTrackingBarButtonItem setTintColor:[UIColor blackColor]];
If you do set it to black like this, the user will never know when it's activated, as the blue color is never shown.
I created a toolbar with a translucent black style like so:
UIToolbar *toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlack;
toolbar.translucent = YES;
I created a button item for it:
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithImage:nil
style:UIBarButtonItemStyleBordered
target:self
action:#selector(mySelector:)];
I noticed that the button when in normal state appears light grey and turns to full black only when I press on it. This seems to be the opposite of how it should function (e.g. Photo app). I'd like it do be black in normal state and lighter when pressed. What am I missing?
Change the barstyle to UIBarStyleBlackTranslucent, as dumb as it sounds, and I believe it returns it to normal.