UIBarButtonItem Appearance and first Application Start - ios

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?

Related

UINavigationController did't works on iOS7 like on iOS6.1 simultaneous

I have this problem, on iOS 7 the app works fine:
On iOS 6.1 the bar did't work. The space was wrong, the button position and all the objects are displayed on wrong position.
The statusbar has changed a lot from iOS7 onwards- you can read about that here: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/Bars.html#//apple_ref/doc/uid/TP40006556-CH12-SW1
A better question would be- how do you like your status bar to behave on iOS 6.1 ?
Regarding the left bar button item, in order to make the iOS6.1 button look like the iOS7.0 button, you will have to create a custom one- this can be done. e.g. create an arrow image similar to the iOS7 one (I call that "back_arrow.png" in the following code) and write the following if it needs to look like the iOS7.0 button (check for the iOS version before writing the following, write it only for iOS version<7.0)
UIImage * backButtonImage = [UIImage imageNamed: #"back_arrow.png"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage: backButtonImage forState: UIControlStateNormal barMetrics: UIBarMetricsDefaultPrompt];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage: backButtonImage forState: UIControlStateNormal barMetrics: UIBarMetricsDefaultPrompt];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],
UITextAttributeTextColor,
[UIFont fontWithName:#"HelveticaNeue-Bold" size:14],
UITextAttributeFont,
[UIColor colorWithRed:70.0/255.0 green:120.0/255.0 blue:251.0/255.0 alpha:1.0],
UITextAttributeTextShadowColor, nil];
NSDictionary *highlightedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor clearColor],
UITextAttributeTextColor,
[UIFont fontWithName:#"HelveticaNeue-Bold" size:14],
UITextAttributeFont,
[UIColor colorWithRed:70.0/255.0 green:120.0/255.0 blue:251.0/255.0 alpha:0.7],
UITextAttributeTextShadowColor, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes: attributes
forState: UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes: highlightedAttributes
forState: UIControlStateHighlighted];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0,0) forBarMetrics:UIBarMetricsDefaultPrompt];

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

iOS: adjusting position of UINavgationBar title

I changed the font & size of the UINavigationBar Title, but doing so made the title not align properly anymore so I thought this "setTitlePositionAdjustment:" should work but it does not (unrecognized selector). How do I adjust the titleĀ“s position?
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"Cochin-Bold" size:24.0],
UITextAttributeFont,
nil]];
[[UINavigationBar appearance] setTitlePositionAdjustment:UIOffsetMake(0, 10)]; // Crash
You need to call the method setTitleVerticalPositionAdjustment:forBarMetrics: instead.
For example:
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:10.0 forBarMetrics:UIBarMetricsDefault];
Check the UINavigationBar class reference for more details on the method.

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

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