UINavigationBar Flash on iOS 7 - ios

Whenever my application is launched (only on iPad) the navigation bar flashes white briefly then pops into it's bar tint color. You can view an animated gif here:
I am setting the tint on a UINavigationController subclass and this config works perfectly on iPhone.
//This returns a UIColor
self.navigationBar.barTintColor = [[IGVThemeManager sharedManager] themeColor];
self.navigationBar.tintColor = [UIColor whiteColor];
self.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName : [UIFont fontWithName:#"HelveticaNeue-Light" size:20]};
I've also tried removing the subclass and manually setting the bar tint color via Interface Builder and still have the same "flash" results. Any ideas on what else may be causing this? This happens on the simulator and on device. Note: this navigation controller exists as part of a split view controller if that helps with any ideas.

Move you code into:
- (void)viewDidLayoutSubviews
This will do the trick.

Remove the code that you currently have and try adding this to your appdeletgate.m. If it still flashes then there is something else going on.
Note: In order to color my navigation bar I added a blue image to it. The text colors are white
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIImage *NavigationPortraitBackground = [UIImage imageNamed:#"blue_color_header_pic"];
// Set the background image all UINavigationBars
[[UINavigationBar appearance] setBackgroundImage:NavigationPortraitBackground forBarMetrics:UIBarMetricsDefault];
// Set the text appearance for navbar
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor whiteColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Helvetica Neue" size:21], UITextAttributeFont,
nil]];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];
// Override point for customization after application launch.
return YES;
}

This might be a little late - I was having the same issue and could not figure out why. I was calling:
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
I had needed that for a different view that I had used for a template and accidentally left that in there. Removing this call fixed it.

Related

set iOS status bar text color to black

On one of my viewControllers I'm setting the NavigationBar programatically (to White with Black tint color)
All is well, but the text of the statusBar stays white (therefore not visible)
The code:
[self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
[self.navigationController.navigationBar setTranslucent:NO];
You can change navigationBar.titleTextAttributes and set title color and font.
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor],UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
adding
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
Did the trick...

MFMailComposeViewController appearance setTintColor getting lost iOS 7

This question is for Xcode 5 running iOS 7 and is super weird. I am trying to set all the UInavigation and UIBarButtonItem text colors to white.
So in my app launch delegate I set the code as.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIImage *NavigationPortraitBackground = [UIImage imageNamed:#"button_header_blue"];
// Set the background image all UINavigationBars
[[UINavigationBar appearance] setBackgroundImage:NavigationPortraitBackground forBarMetrics:UIBarMetricsDefault];
// Set the text appearance for navbar
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor whiteColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Helvetica Neue" size:21], UITextAttributeFont,
nil]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState: UIControlStateNormal];
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
// Override point for customization after application launch.
return YES;
}
If I launch "send mail" action twice
- first time I see UIBarButton items white. I look at it and hit the Cancel button
- second time I see them all of them grayed out and barely visible except for the title.
- This is happening in both my iPhone simulator and iPhone running iOS 7.
how can I fix this?
I had to do it this way in order for it to work on iOS 7
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController.navigationBar setTintColor:[UIColor whiteColor]];
[mailViewController.navigationBar setBarTintColor:[UIColor whiteColor]];
....

Custom navigation bar changes in one viewcontroller

I am working with a custom navigation bar.
In my AppDelegate I've done this.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbar"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes: #{
UITextAttributeTextColor: [UIColor whiteColor],
UITextAttributeTextShadowColor: [UIColor whiteColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
UITextAttributeFont: [UIFont fontWithName:#"Carrois Gothic" size:18.0f]
}];
On viewController level I put buttons inside the navigationController. In all viewControllers I have only one button inside the navigationbar.
But in one VC I need to set 2 buttons and I also change the backgroundImage of the navigationbar. So what I copied the same code as above in the ViewDidLoad but now with other image. This is working.
But now I want in all other VC's the first navigationbar. So in my viewDidDisappear I copied again the code with the other image again.
The following is going wrong:
The background image is not changing
The leftbarbutton is not going away
Can anybody help me with this ?
PS: I am working with a tabbarcontroller. So if I say switching VC's I mean going to another tab in the tabbarcontroller
Do not use the appearance proxy in the ViewController. Just set the background directly:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"navbar"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setTitleTextAttributes: #{
UITextAttributeTextColor: [UIColor whiteColor],
UITextAttributeTextShadowColor: [UIColor whiteColor],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],
UITextAttributeFont: [UIFont fontWithName:#"Carrois Gothic" size:18.0f]
}];

NavigationBar title is coming in black color

I am using a UINavigationBar in my app with UITabBar.
On the first tab, the navigation bar title is coming properly as a white title with the default background color, but on the second tab it's not working in the same way. I'm not using any code to change the title color or the navigation bar's tintColor.
First view:
http://img407.imageshack.us/img407/7192/4go.png
Second View:
Why is the second view's UINavigationBar title drawn in this black color?
Generally, you can not change default color of UINavigationBar Title. In case of If you want to change color of UINavigationBar Title than you need to customize UINavigationBar. so put code for your second ViewController for more Understanding.
EDIT:
After searching, I found that You can change title color of UINavigationBar by
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
This code is working in iOS5 and later.
Most of the above suggestions are deprecated now, for iOS 7 use -
NSDictionary *textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],NSForegroundColorAttributeName,
[UIColor whiteColor],NSBackgroundColorAttributeName,nil];
self.navigationController.navigationBar.titleTextAttributes = textAttributes;
self.title = #"Title of the Page";
Also, checkout the NSAttributedString.h for various text properties that could be set.
Try this in AppDelegate:
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor whiteColor]}];
This will allow you to change the colors
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
Use this bit of code for iOS7 as UITextAttributeTextColor has been deprecated.
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor orangeColor] forKey:NSForegroundColorAttributeName];
This code changes the text of all the navigationBar, with this code the text can be customized 100%.
in appDelegate:
//custom text navBar
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0x73/255.0 green:0x47/255.0 blue:0x41/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor colorWithRed:0x1D/255.0 green:0x1D/255.0 blue:0x1B/255.0 alpha:1], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"yourFont" size:20], UITextAttributeFont, nil]];

change tabbar text color,iPhone

I have created a tabbar programmatically.
Can we change color of title of the tabbar item?
Default is white, and i m trying to make it black.
something like
tabbaritem.text.textcolor=[UIcolor Blackcolor];
Thanks
In iOS5 you use the appearance proxy to change the title color:
For a specific tabbar item:
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"AmericanTypewriter" size:20.0f], UITextAttributeFont,
[UIColor yellowColor], UITextAttributeTextColor,
[UIColor redColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
Or replace self.tabBarItem with [UITabBarItem appearance] to change all your tabbar items.
If you want to change them all , I suggest you place the code on appdelegate didFinishLaunchingWithOptions:
Just something else ...
To set your standard appearance in iOS 5:
In your AppDelegate.m do:
[[UITabBar appearance] setTintColor:myColor]; //or whatever you want to change
Saves you a lot of work.
Maybe this updated code helps someone:
[UITabBarItem.appearance setTitleTextAttributes:#{
NSForegroundColorAttributeName : [UIColor lightGrayColor] } forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:#{
NSForegroundColorAttributeName : [UIColor whiteColor] } forState:UIControlStateSelected];

Resources