Custom navigation bar changes in one viewcontroller - ios

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]
}];

Related

UINavigationBar Flash on iOS 7

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.

xcode - Design / Redesign MailController / MFMailComposeViewController

Is it possible to Redesign the MFMailComposeViewController?
How?
The App Dropbox can do it.
Picture: http://jonathangurebo.tumblr.com/post/40436277822
Can I change the "MessageUI.framework"?
To answer your request regarding customizing the appearance of ALL navigation bars in the app, use this in your application:didFinishLaunchingWithOptions: in your app delegate:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"image"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[[UINavigationBar appearance] setAlpha:1];
//change background image and tint color for navigation buttons
// Set the text appearance for navbar
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:2 forBarMetrics:UIBarMetricsDefault]; //change vertical appearance of navigation bar title
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(1, 1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"HelveticaNeue" size:22], UITextAttributeFont,
nil]]; //set custom font info

How can I set the titletextattributes for a UINavigation bar for just one view controller?

I'm trying to change the font size of just one of my view controllers because it lends itself to more text, thus requiring smaller font size than my other views. I am setting the navigation bar attributes in the appdelegate during didFinishLaunchingWithOptions, and then setting the font for my view controller in question during the viewDidLoad. However, when I go back a screen, or forward, the changes I made to the navigation bar are retained, i.e. the smaller font. Is there a way around this? For example setting the font back to normal upon exiting the view or something?
Cliffsnotes: Trying to set font in just one view controller, but once I set it, it applies to all view controllers.
Code is as follows:
In AppDelegate:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbar.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"QuicksandBold-Regular" size:24.0],
UITextAttributeFont,
nil]];
In the view controller viewDidLoad:
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"QuicksandBold-Regular" size:18.0],
UITextAttributeFont,
nil]];
The navbar is shared by all view controllers in the navigation controller. So once you change the navbar, all view controllers in the same nav stack will be affected. One option would be to set a custom titleView for this one view controller.
self.navigationItem.titleView = ... // some UILabel with the desired formatting
This way, only the one view controller shows the custom title.
Another option would be to change the navbar's appearance in the view controller's viewWillAppear method and then reset it in the view controller's viewWillDisappear method. But this approach may not be as smooth as just using a custom titleView.
So, now yours attributed keys is deprecated. Use this keys:
NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor], NSForegroundColorAttributeName,
[UIColor whiteColor], NSShadowAttributeName,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], NSShadowAttributeName,
[UIFont fontWithName:#"QuicksandBold-Regular" size:24.0], NSFontAttributeName,
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];

UIBarButtonItem Appearance and first Application Start

we use the appearance system of iOS 5 to style our application, we also style the UIBarButtonItem like this:
[[UIBarButtonItem appearance] setBackgroundImage:button
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
normalColor, UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:kFontName size:kFontSize], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
But have a buttonitem at the start view controller of our navigation view controller, but the first time this screen is displayed this button has its default background.
When I change the order of both statements the button has the correct background but the wrong text.
Any ideas how to solve this problem?

Resources