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.
Related
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
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;
}
I have a UIBarButtonItem on a navigation bar. When I enter my app, it starts out white (the desired color) and then switches abruptly to a faded out gray color. If I interact with the app and later return to the same view controller, the button returns to the white color. What could be causing this?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Logout" style:UIBarButtonItemStyleDone target:self action:#selector(handleBack:)];
[backButton setTitleTextAttributes:[NSDictionary dictionaryWithObject: [UIColor whiteColor]
forKey: UITextAttributeTextColor] forState:UIControlStateNormal];
//[backButton setTintColor: [UIColor whiteColor]];
self.navigationItem.leftBarButtonItem = backButton;
[self.navigationController.navigationBar setBarStyle: UIBarStyleBlack];
[self populateSpinners];
isCategoryPicker = true;
[self.view setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];
}
I've tried setting the tint color at the view level, the toolbar level, and at the button level and nothing seems to be working. Any help is appreciated!
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.
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.