Change tint color on email dialog opened through ActivityView - ios

We have white tintColor in whole app.
See on cancel button. Is is white.
How can we change its color?

You can do this by changing [UIBarButtonItem appearance], e.g.:
NSDictionary *textAttributes = #{UITextAttributeTextColor: [UIColor blackColor]};
[[UIBarButtonItem appearance] setTitleTextAttributes:textAttributes forState:UIControlStateNormal];

Try this :-
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Title" style:UIBarButtonItemStyleBordered target:self action:nil];
[barButtonItem setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItems = #[barButtonItem];
Change title and color according to your requirement.

Related

iOS - Change only backBarButtonItem text color on a navigation bar

I'm trying to change the color of the backBarButtonItem on a navigation bar in my app (iOS 9+).
I can do this with :
[[UIBarButtonItem appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal];
But this will change the color for all UIBarButtonItems on the navigation bar and I only want to change the back button.
I have tried :
[self.navigationItem.leftBarButtonItem setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal];
and
[self.navigationItem.leftBarButtonItem setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor clearColor]} forState:UIControlStateNormal];
But it doesn't work
NOTE: I want to keep the < arrow of the system back button so using a custom view is not an option unless I use a custom image
In the end I used the following solution:
1. Set the general appearance of UIBarbuttonitem BEFORE adding the right bar button item
[[UIBarButtonItem appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor blueColor]} forState:UIControlStateNormal];
2. Then set the right bar button item and its specific appearance
UIBarButtonItem *rigthBtn = [[UIBarButtonItem alloc] initWithTitle:#"title" style:UIBarButtonItemStylePlain target:self action:#selector(rightBtnTapped:)];
[rigthBtn setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateNormal];
[self.navigationItem setRightBarButtonItem:rigthBtn];
As per my comment posting sample code
UIButton *useButton = [UIButton buttonWithType:UIButtonTypeCustom];
useButton.frame = CGRectMake(0, 0, 20,17);
useButton.layer.masksToBounds = NO;
useButton.layer.shadowOffset = CGSizeMake(3, 3);
useButton.layer.shadowRadius = 3;
useButton.layer.shadowOpacity = 0.1;
useButton.layer.shadowColor = [UIColor blackColor].CGColor;
useButton.backgroundColor = [UIColor clearColor];
useButton.tintColor = [UIColor whiteColor];
[useButton setImage:[UIImage imageNamed:#"image if any"] forState:0];
[useButton addTarget:self action:#selector(btnBackTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:useButton]];
`
One year too late but did you tried to set the tintColor? I dont know your syntax but in swift it would be:
navigationController.navigationBar.tintColor = UIColor.COLOR

NAvigation bar not appear

I want to make my NavigationbarClear color. So I tried like this in my ViewDidLoad
self.navigationController.navigationBar.hidden=NO;
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage=[UIImage new];
self.navigationController.navigationBar.translucent=YES;
self.navigationController.navigationBar.topItem.titleView.tintColor=[UIColor blackColor];
self.navigationController.navigationBar.topItem.title=[lan GetConvertedLanguageString:#"My Profile"];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"backarrow"] style:UIBarButtonItemStylePlain target:self action:#selector(revealToggle :)];
[self.navigationController navigationBar].tintColor = [UIColor whiteColor];
But nothing visible in my view controller. Whats wrong with this code? Please help me.
Thanks
Pick up navigation controller scene and then pickup navigationbar (see in pic) after that set the clear color from showutilites>attribute insepecter also you can change title color from here
Screenshot
Code
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage=[UIImage new];
self.navigationItem.title = #"1234";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Left" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
[self.navigationController navigationBar].tintColor = [UIColor whiteColor];
So,I guess,your background of View is White,so you cannot see white text.
Note
navigationBar.titleTextAttributes
Display attributes for the bar’s title text.
navigationBar.tintColor
The tint color to apply to the navigation items and bar button items.

leftBarButtonItem position is incorrect

I am attempting to add a custom button in the nav bar, however the placement in the nav bar is off to the left. Here is what I'm looking at (note the "Menu" button is too far left):
Here is how I'm adding the button to the current viewcontroller. setupMenu is called in ViewDidLoad.
-(void)setupMenu{
self.navigationItem.leftBarButtonItem = [self leftMenuBarButtonItem];
}
- (UIBarButtonItem *)leftMenuBarButtonItem {
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"GuidanceNavMenu", nil) style:UIBarButtonItemStylePlain target:self action:#selector(popToOpenMenu)];
NSMutableParagraphStyle *paragraphStyle = NSMutableParagraphStyle.new;
[menuButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont openSansFontOfSize:14.0f], NSFontAttributeName,
[UIColor blackColor], NSForegroundColorAttributeName,
nil]
forState:UIControlStateNormal];
return menuButton;
}

setting the text color of UIBarButtonItem by appearance proxy

Here's what is being set and it's close to the color I need:
NSDictionary *barButtonItemTitleAttributesEnabled = #{
NSFontAttributeName:[UIFont MRFontLightOfSize:17],
NSForegroundColorAttributeName:[UIColor whiteColor]
};
NSDictionary *barButtonItemTitleAttributesDisabled = #{
NSFontAttributeName:[UIFont MRFontLightOfSize:17],
NSForegroundColorAttributeName:[UIColor colorWithWhite:1.0f alpha:0.25f]
};
[[UIBarButtonItem appearance] setTitleTextAttributes:barButtonItemTitleAttributesEnabled forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:barButtonItemTitleAttributesDisabled forState:UIControlStateDisabled];
But I'd prefer to somehow set the disabled text color to the same color as the selected state, is there a way to do that with the appearance proxy calls?
Also tried this:
NSDictionary *barButtonItemDisabled = [[UIBarButtonItem appearance] titleTextAttributesForState:UIControlStateSelected];
[[UIBarButtonItem appearance] setTitleTextAttributes:barButtonItemTitleAttributesEnabled forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:barButtonItemDisabled forState:UIControlStateDisabled];
resolved by removing TextTitleAttribute code above and setting the toolBar tintColor appearance proxy:
[[UIToolbar appearance] setTintColor:[UIColor whiteColor]];
this made it so that just enabling or disabling the buttons set them to the right color.
If you want to give different colours for different items then you should use
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
initWithTitle:#"Done" style:UIBarButtonItemStylePlain
target:self action:#selector(done)];
[doneButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
Otherwise you should just simply write
[toolBar setTintColor:[UIColor whiteColor]];

Can't change the background for UIBarButtonItem

I need to change the default (which was already declared in my AppDelegate) background for UIBarButtonItem in one ViewController.
So, In my AppDelegate I have:
UIImage *navBarItemBackground = [UIImage imageNamed:#"navbar_button_green"];
[[UIBarButtonItem appearance] setBackgroundImage:navBarItemBackground
forState:UIControlStateNormal
style:UIBarButtonItemStyleBordered
barMetrics:UIBarMetricsDefault];
And when I need to restore the default background for the button - I implement in my viewController:
self.navigationItem.rightBarButtonItem = nil;
UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:#"Сохранить" style:UIBarButtonItemStyleBordered target:self action:#selector(clickOnSend:)];
[rightBarItem setBackgroundImage:[UIImage imageNamed:#""] forState:UIControlStateNormal style:UIBarButtonItemStyleBordered barMetrics:UIBarMetricsDefault];
self.navigationItem.rightBarButtonItem = rightBarItem;
But I think that it's not correct to set the empty file as the image. Is there more simple way to implement this behaviour? Thanks!
If you want to change only one or several UIViewController's UIBarButtonItems backgroundImage, you'd better change in the specific UIViewControllers as the latter case you use. while [[UIBarButtonItem appearance] setBackgroundImage:forState:style:barMetrics:]; will change all the UIBarButtonItems background image, which maybe not the better one.
You should change your code to this:
UIBarButtonItem * rightBarItem = [[UIBarButtonItem alloc]
initWithTitle: #"Сохранить"
style: UIBarButtonItemStyleBordered
target: nil action: nil];
UIImage *navBarItemBackground = [[UIImage imageNamed:#"navbar_button_green"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 6)];
[[UIBarButtonItem appearance] setBackgroundImage:navBarItemBackground
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[self.navigationItem setBackBarButtonItem: rightBarItem];

Resources