I am updating my big project to ios7 . And When I update left navigation button have problem .
I don't understand What is problem .
ios6: left button image haven't problem :
ios7: left button have problem
Also when I go next viewcontroller back button have same problem in ios7:
I am using for menu this image: link . image is transparent .
How can I solve this problem in ios7 .
it's big project and ı can't share all code.When I read article , article says it's problem is setTintColor. right ?
sorry my English.
Thank you .
I changed global tint and I use this way to keep my UIBarButtonItem normal.
#define kColorGlobalTint [UIColor redColor]
UIColor *defaultColor = [UIView appearanceWhenContainedIn:[UINavigationBar class], nil].tintColor;
[[UIView appearance] setTintColor:kColorGlobalTint];
[[UIView appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:defaultColor];
[[UINavigationBar appearance] setBarTintColor:kColorGlobalTint];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
what is the color for your image used in the left top navigational bar button? you can try to change the following.
Give the bar button item tint = clear color
Give the button item tint under the bar button item as Default and its background as clear color.
change Alpha Value of button item to 1.
I solved the problem .I added to viewDidLoad method
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
}
else
{
[self.navigationController.navigationBar setTintColor:[UIColor colorWithRed:.694 green:.164 blue:.105 alpha:1.0f]];
}
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 an issue changing the font for the Title in my navigation controller.
Here is my code (from my subclass of UINavigationController):
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSDictionary * attributes = #{UITextAttributeTextColor :[UIColor whiteColor],
UITextAttributeFont :[UIFont fontWithName:#"Blanch" size:50],
};
self.navigationBar.titleTextAttributes = attributes;
CGFloat verticalOffset = -8;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
UIImage *image = [UIImage imageNamed:NAVBAR_IMAGE];
[self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
This is what it looks like:
If I comment out the line setting the font this is what it looks like (as expected with the vertical offset):
The only reason the vertical offset is there is that I thought it might have solved the problem. I don't need it and it is commented out now, but it does NOT change the output - it still looks the same just lower on the NavBar.
Any ideas how to solve this? I think it may be that the custom font has a lot of line-spacing
which I guess could be the problem.
I have been trying to find a way to change the origin/height/baseline alignment of the title but can't see a way to do any of these.
Any idea how to solve this problem ?
Create a container UIView which is the same width as your label, and height of UINavigationBar (around 46 pixels?). Set clipsToBounds on this container view to YES. Now add your label to this container view, and make the container view the titleView.
Setting Navigationbar image for ios5
if ([self.navigationController.navigationBar respondsToSelector:#selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"YOUR_NAVIGATION_BAR_IMAGE"] forBarMetrics:UIBarMetricsDefault];
}
Setting Navigationbar image for ios6
if([[UINavigationBar appearance] respondsToSelector:#selector( setBackgroundImage:forBarMetrics:)]){
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"YOUR_NAVIGATION_BAR_IMAGE"] forBarMetrics:UIBarMetricsDefault];
after than create label in center on your navigation bar center with your title.
I am using iOS 5 UINavigationBar's UIAppearance protocol in order to customise all my navigation bars.
Here is my customisation function:
- (void)customizeApperance
{
[[UINavigationBar appearance] setTintColor:[UIColor clearColor]];
[[UINavigationBar appearance] setAlpha:0.7];
UIImageView *titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"title.png"]];
[[UINavigationBar appearance] setTitleView:titleView];
}
I have two problems:
The first is that the colour not appearing as clearColor but black. Any suggestions?
The title view is not appearing at all. Ray Wenderlich shows how to do that by adding a: [[rootViewController navigationItem] setTitleView: [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"miniLogo.png"]]] in applicationDidFinishLaunching. But the problem with this is that the title view would only be added in the root view controller. I am using a UINavigationController and when I tired to replace the rootViewController with navigationController (the name of my navigation controller in AppDelegate), I cannot see the title view at all. How can I fix that? Why isn't it working in customizeApperance()? Isn't the whole point of using appearance is to just create a title view once (as I did above the function) and have it global in all navigation bars? How can I achieve that?
[UIColor clearColor] is a fully transparent color (alpha = 0). Setting that as tint color makes the (black) background shine through. Perhaps you want [UIColor whiteColor] ?
titleView is a property of UINavigationItem, and each view controller has it's own navigationItem. Therefore you cannot set a title view globally. But you can set the background image of UINavigationBar with the appearance protocol, perhaps that helps:
[[UINavigationBar appearance] setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
Have you tried titleView.opaque = NO;? If that's set to YES (i.e. by default, since you're using initWithImage:), the drawing system will assume your view fills its entire bounds, and won't bother drawing anything that overlaps its frame.
setTitleView: is a method on NavigationItem. But you are calling it on navigation bar
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!