Set text font size of leftbarbuttonitem in iOS7 - uinavigationbar

So I've been able to change the text size and color of the main text in the UINavigationBar like so:
[[UINavigationBar appearance] setTitleTextAttributes:#{
UITextAttributeTextColor: [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1.0],
UITextAttributeTextShadowColor: [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeFont: [UIFont fontWithName:#"Arial-Bold" size:0.0],
}];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
However, the font size of the leftbarbuttonitem is still too large. How do i reference the leftbarbuttonitem so that i can set the text style to it?
I've tried stuff like
[UINavigationBar leftBarButtonItem]
[[UINavigationBar navigationItems] leftBarButtonItem]
[[UINavigationBar appearance] leftBarButtonItem]
// and many others
etc...
But xcode keeps complaining that it doesn't exist, and I have not been able to reference it.
Can someone tell me how to set the text size for the leftBarButtonItem based on my code above?
Thanks

The following will work:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:(NSDictionary *) forState:(UIControlState)];
Keep note, that the UINavigationBar uses the UIBarButtonItem, so you need to style that object when it's contained in a specific view (reference by it's class). This applies in several other places. Another use case could be this, where A, B, and C are 3 distinct UINavigationControllers
[[UIBarButtonItem appearanceWhenContainedIn:[A class], [B class], nil] setTitleTextAttributes:(NSDictionary *) forState:(UIControlState)];
[[UIBarButtonItem appearanceWhenContainedIn:[C class], nil] setTitleTextAttributes:(NSDictionary *) forState:(UIControlState)];
In the above sample, UIBarButtonItems in UINavigationControllers A & B will receiving the similar styling whereas UINavigationController C's UIBarButtonItems will have their own distinct styling.

Related

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

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

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?

IOS 5 How to change the color of back button in a navigation bar?

I want to change the color of back button of a navigation bar to make it look like this
Set the backBarButtonItem's tintColor:
self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor];
TIP: If you want this to be applied to all UIBarButtonItem instances in your application by default, then you can use the new UIAppearance API to do just that:
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
The first line of jacob's answer didn't work for me because the backBarButtonItem was NULL. It is NULL because it's been created later automatically when switching to an other ViewController. At that time you can set the title of the button with
self.title = #"nice title"; // self is here the view(controller) within the popoverController
but you can't set the tintColor.
What worked for me, was to create a new UIBarButtonItem without any style. Then set the title and color propertys and set it as backBarButtonItem.
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
backButton.title = #"go back - now!";
backButton.tintColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.7 alpha:1.0];
self.navigationItem.backBarButtonItem = backButton;
[okButton release];
If you want to make the button look exactly like in your picture, you may use an image, too:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:#"back_button_bg"]
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
The background image must be a resizable image for good results.
Best way I found to set it globally or locally is
[[UIBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"AmericanTypewriter" size:0.0], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]];
try this It is working for me...

Resources