How to change the bottom toolbar tint color without changing the navigator bar tint? - ios

I want to set the navigator bar tint to white but the bottom tool bar tint to red.
The navigator bar tint is set at storyboard, and the tool bar tint is set in code.
self.navigationController?.toolbar.tintColor=UIColor.redColor()
But the code dose not work.

Swift:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
var nav = self.navigationController?.navigationBar
nav?.barStyle = UIBarStyle.Black
nav?.tintColor = UIColor.whiteColor()
nav?.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orangeColor()]
}
Objective-C:
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, [UIColor whiteColor], UITextAttributeTextShadowColor, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];
textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], UITextAttributeTextColor, nil];
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
[[UIToolbar appearance] setTintColor:[UIColor redColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

In Objectivec-c
UIToolbar *doneToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0,
self.view.frame.size.height-44, 320, 44)];
doneToolbar.translucent=NO;
doneToolbar.barTintColor=[UIColor redColor];
[self.view addSubview:doneTool bar];
for more information click here

Related

set iOS status bar text color to black

On one of my viewControllers I'm setting the NavigationBar programatically (to White with Black tint color)
All is well, but the text of the statusBar stays white (therefore not visible)
The code:
[self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];
[self.navigationController.navigationBar setTranslucent:NO];
You can change navigationBar.titleTextAttributes and set title color and font.
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor],UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
adding
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
Did the trick...

How to change these colors on Navbar?

I have succesfully change the navbar button with this:
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:26.0/255 green:132.0/255 blue:182.0/255 alpha:.5]];
What about if I want to change the color of the title (from black) or the color of the button?
This is what I have in my App Delegate in a method specially for changing appearances.
// set button tint colour to white
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// set the bar tint colour to purplish
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:.2 green:.458823529 blue:.592156863 alpha:1.0]];
// set title text label colour to white
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
For navigation bar title color in iOS7 you should use the setTitleTextAttributes of UINavigationBar appearance
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-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
For more navbar customization refer http://www.appcoda.com/customize-navigation-status-bar-ios-7/

navigationBar.barTintColor always black and not possible to change it

The navigationBar.barTintColor in my app is always black, and there is no way I can change it. I checked all classes and I never set it to black, but I do set it to UIColor clearColor. Still, the bar is black. Any suggestions?
Edit:I found out that the problem is with my [UIColor clearColor], when I change it to any other color it changes the color like it should, but clearColor makes it appear black.
Have a look there
Try modifying the Style and Translucent attributes on the navigation bar (top right in image).
If you are having problems modifying the status bar color, try adding this to your .plist (line below).
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
Finally, here's some code you may want.
// Status bar color
[[UIApplication sharedApplication] setStatusBarStyle:yourStyle];
// Navigation bars color
[UINavigationBar appearance].barStyle = yourStyle;
[UINavigationBar appearance].barTintColor = [UIColor yourColor];
// Navigation bars items color
[UINavigationBar appearance].tintColor = [UIColor yourColor];
If its IOS7 try the code below
[[UINavigationBar appearance]setBarTintColor: [<Specify the UIColor you want>];
In IOS6 try this
[[UINavigationBar appearance] setTintColor: [<Specify the UIColor you want>];
Edit:
I think you have given
self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
This will give black color. If you want any specific tint color, it must be specifed after clearing
self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
self.navigationController.navigationBar.barTintColor = [UIColor <specify your color>];
if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleTextAttributes:
#{
UITextAttributeTextColor: [UIColor whiteColor],UITextAttributeTextShadowColor: [UIColor clearColor],UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)],UITextAttributeFont: [UIFont fontWithName:#"ArialMT" size:18.0f]
}];
CGFloat verticalOffset = -4;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}
else
{
[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
// Uncomment to change the color of back button
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
// Uncomment to assign a custom backgroung image
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav_bg_ios7.png"] forBarMetrics:UIBarMetricsDefault];
// Uncomment to change the back indicator image
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:#""]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:#""]];
// Uncomment to change the font style of the title
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:#"ArialMT" size:18.0], NSFontAttributeName, nil]];
CGFloat verticalOffset = -4;
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:verticalOffset forBarMetrics:UIBarMetricsDefault];
}
In iOS 7 try:
[self.navigationController.navigationBar setTranslucent:NO];

MFMailComposeViewController bar background color not changing in iOS7

I'm trying to change the background color of the MFMailComposeViewController in iOS7 but I cannot make it work.
I'm using the following snipped:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
if([picker.navigationBar respondsToSelector:#selector(barTintColor)]) {
// iOS7
picker.navigationBar.barTintColor = READER_NAVIGATION_BAR_BACKGROUND_COLOR;
// Set back button arrow color
[picker.navigationBar setTintColor:READER_NAVIGATION_BAR_BACK_BUTTON_ARROW_COLOR];
// Set Navigation Bar Title Color
[picker.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:READER_NAVIGATION_BAR_TITLE_NORMAL_FONT_COLOR forKey:UITextAttributeTextColor]];
// Set back button color
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:READER_NAVIGATION_BAR_BUTTONS_FONT_COLOR, UITextAttributeTextColor,nil] forState:UIControlStateNormal];
}
Does anybody knows how to change the bakcground color of the MFMailComposeViewController in iOS7?
The trick here is to call 'appearance methods' such as
[UINavigationBar appearance].barTintColor = [UIColor whiteColor];
[UINavigationBar appearance].tintColor = [UIColor redColor];
BEFORE calling to
[[MFMailComposeViewController alloc] init];
This way the color scheme will be applied to the mail composer.
It may be returned back to defaults in mailComposeController:didFinishWithResult:
try this. worked for me.
MFMailComposeViewController* myailViewController = [[MFMailComposeViewController alloc] init];
// set other attributes of mailcomposer here.
myMailViewController.mailComposeDelegate = self;
[myMailViewController.navigationBar setTintColor:[UIColor whiteColor]];
[self presentViewController:myMmailViewController animated:YES completion:nil];
Swift 3 solution:
extension MFMailComposeViewController {
override open func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
}
open override func viewDidLoad() {
super.viewDidLoad()
navigationBar.isTranslucent = false
navigationBar.isOpaque = false
navigationBar.barTintColor = UIColor.white
navigationBar.tintColor = UIColor.white
}
}
For iOS8:
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
Or
navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor yellowColor] forKey:UITextAttributeTextColor];
try this but one thing BarTintColor available only iOS7
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
This color is made translucent by default unless you set the translucent property to NO.
or try this link it will more helpful you
Changing MFMailComposeViewController's toolbar color
Try the following code
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor blackColor]];
// Your usual code follows here ......
#SoftDesigner's answer:
As of iOS 9:
[UINavigationBar appearance].tintColor = yourFavoriteColor;
does not work on the MFMailComposeViewController.
The rest of the answer works (I used it), but as far as I can tell you're stuck with Apple's colors for the nav bar buttons.
Hope this saves someone else some angst.
First present the MFMailComposeViewController then change its tintColor
[self presentViewController:emailDialog animated:TRUE completion:nil];
[[UINavigationBar appearance] setBackgroundImage:nil
forBarPosition:UIBarPositionTopAttached
barMetrics:UIBarMetricsDefault];
I had a problem that prevented me from setting the background colour. Turns out I had some other code elsewhere setting the background image to [UIImage new].
The following code fixed it:
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:nil];

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.

Resources