iOS: adjusting position of UINavgationBar title - ios

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.

Related

Is there a way to change title in navigation bar to Italic, Bold and underlined without changing font?

I use the UIAppearance to change attributes of my title in Navigation Bar like so:
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [MM mainTitleColor]}];
But I have not found the way to make text underlined or italic, is there a way to do this without changing the font alltogether?
No. These properties you cant change unless font changing. Because the available keys under the appearance proxy are
UITextAttributeFont
UITextAttributeTextColor
UITextAttributeTextShadowColor
UITextAttributeTextShadowOffset
Change these properties to customize the UINavigationBar
If you looking for font change, then see the below example
[[UINavigationBar appearance] setTitleTextAttributes:#{
UITextAttributeTextColor: TEXT_COLOR,
UITextAttributeTextShadowColor: SHADOW_COLOR,
UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeFont: [UIFont fontWithName:#"Arial-Bold" size:0.0],
}];
Try this one.
You have to customise your navigation controller with adding a imageview.
UIFont *yourFont = [UIFont fontWithName:#"Helvetica-BoldOblique" size:[UIFont systemFontSize]];
if ([[UINavigationBar class]respondsToSelector:#selector(appearance)]) {
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"myimage.png"] forBarMetrics:UIBarMetricsDefault];
}
[[UINavigationBar appearance] setTitleTextAttributes:#{
UITextAttributeTextColor : [UIColor clearColor],
UITextAttributeTextShadowColor : [UIColor blackColor],
UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
UITextAttributeFont : yourFont
}];
You can use :
Optima-BoldItalic
TimesNewRomanPS-BoldItalicMT
Baskerville-BoldItalic
HelveticaNeue-BoldItalic
TrebuchetMS-Bold
Helvetica-BoldOblique
You can try below code to make your text italic and bold.
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:#"HelveticaNeue-BoldItalic" size:21.0], NSFontAttributeName, nil]];
[self setTitle:#"Title text"];

Set text font size of leftbarbuttonitem in iOS7

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.

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

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

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