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

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

Related

iOS:Is it possible to change appearance of a UI element back to default appearance?

I am setting appearance of UIBarButtonItem using -appearance method.
How can I change it back to iOS default appearance?
Here I am changing appearance of UIBarButtonItem:
NSDictionary *textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithHex:0x3A4047],
UITextAttributeTextColor,
[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0],
UITextAttributeTextShadowColor,
[UIFont fontWithName:#"Helvetica-Bold" size:13.0],
UITextAttributeFont,
nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:textAttributes
forState:UIControlStateNormal];
Now at some point can I revert all that appearance proxies that I have applied to default proxies?
[[UIBarButtonItem appearance] setTitleTextAttributes:nil
forState:UIControlStateNormal];
Create an NSDictionary with all of the default attributes before you create *textAttributes. Then when you want to make it default set the attributes to the other NSDictionary.

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

UIBarButtonItem style plain change font

Changing the
NSDictionary * barButtonAppearanceDict = #{UITextAttributeFont : font};
[[UIBarButtonItem appearance] setTitleTextAttributes:barButtonAppearanceDict forState:UIControlStateNormal];
Doesn't affect the UIBarButtonItem when using plain...
How can i change the font for the plain style UIBarButtonItem
This still applies to iOS6
This works for me however (with plain BarButtonItem), have just tested it:
[self.myBarButtonItem setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Helvetica" size:22.0],NSFontAttributeName,
nil]forState:UIControlStateNormal];
For using Appearance proxy you can try this:
NSDictionary *attrDict = [NSDictionary dictionaryWithObject: [UIFont fontWithName:#"Helvetica" size:22.0] forKey: UITextAttributeFont];
[[UIBarButtonItem appearance] setTitleTextAttributes: attrDict
forState: UIControlStateDisabled];
[[UIBarButtonItem appearance] setTitleTextAttributes: attrDict
forState: UIControlStateNormal];
Are you sure, that you implement this in your AppDelegate- class? (e.g. in didFinishLaunchingWithOptions-method)
I set the following in the appdelegate and it worked great:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIBarButtonItem appearance] setTitleTextAttributes:#{NSFontAttributeName : [UIFont fontWithName:#"Avenir" size:21.0]} forState:UIControlStateNormal];
}

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