UIBarButtonItem style plain change font - ios

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

Related

UINavigationBar Font properties only seems to adjust title but not breacrumbs portion of view

I used the following in my AppDelegate.m to change the font properties of my UINavigationBar:
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor darkBlue], NSForegroundColorAttributeName,
[UIFont fontWithName:SYSTEM_FONT_TYPE size:SYSTEM_FONT_SIZE*1.2], NSFontAttributeName, nil]];
However, this seems to adjust only the title-displaying font and not the breadcrumb back-tracing portion:
Looking over the class reference, I must be missing it because I don't see anything else to reference as a property or method other than those relating to TitleTextAttributes. What else should I change to change the left text's font?
UIBarButtonItem *backbutton = [[UIBarButtonItem alloc] initWithTitle:#"Menu" style:UIBarButtonItemStyleBordered target:nil action:nil];
[backbutton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor darkBlue],UITextAttributeTextColor,[UIFont fontWithName:TEXTFONT size:16.0f],UITextAttributeFont, nil] forState:UIControlStateNormal];
or alternatively,
[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor darkBlue],[UIFont fontWithName:TEXTFONT size:16.0f],UITextAttributeFont, nil] forState:UIControlStateNormal];

UIBarButtomItem tintColor not working if i change the appearance of UITextField

I have a instance of UIBarButtonItem.
I want to change the tintColor of the UIBarButtonItem to orangeColor.
And I also change the appearance of UITextField to orangeColor in the Appdelegate.
// some view controller
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:nil action:nil];
[barButtonItem setTintColor:[KLStyle colorTitleOrangle]];
// Appdelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UITextField appearance] setTintColor:[UIColor orangeColor]];
}
There is a problem if i don't comment [[UITextField appearance] setTintColor:[UIColor orangeColor]]; , the tintColor of UIBarButtonItem will be wrong. It's still default tintColor blue.
If i comment it, the tintColor of UIBarButtonItem will be correct.
Is there someone known why this will be happen?
Thanks for helping!
Workaround:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor: [UIColor lightGrayColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:24.0/255 green:75.0/255 blue:152.0/255 alpha:1],
NSForegroundColorAttributeName,
[UIColor grayColor],
NSForegroundColorAttributeName,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
NSForegroundColorAttributeName,
nil]
forState:UIControlStateNormal];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor grayColor],
NSForegroundColorAttributeName,
[UIColor grayColor],
NSForegroundColorAttributeName,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
NSForegroundColorAttributeName,
nil]
forState:UIControlStateDisabled];

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

iOS 7 UINavigationBar appearance not working first timeā€¦

I am trying to change the look of the UINavigationBar in my iOS7 app. I am doing the following:
- (void)viewDidLoad
{
[super viewDidLoad];
m_sNumberToCall = #"";
UIBarButtonItem * btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"IconHome.png"] style:UIBarButtonItemStyleBordered target:self action:#selector(btHomeTouched:)];
self.navigationItem.leftBarButtonItem = btn;
self.navigationController.navigationBar.translucent = YES;
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault];
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:#"Helvetica-Bold" size:21.0],
NSFontAttributeName,
nil]];
}
But, the first time I present the UITableViewController it is the standard iOS7 nav bar, then I press home and present it again and it is my new look.
Any ideas why it does not work the first time?
Don't change the appearance but the navigation bar directly. The appearance affects only the future instances but not the already created ones.
Change:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault];
to:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"TVCNavBack.png"] forBarMetrics:UIBarMetricsDefault];
The answer before only helps you with the background image but not with the title text attributes.
You don't need to change your code but all you have to do is move it to
applicationDidFinishLaunchingWithOptions
in your AppDelegate.m file.

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

Resources