leftBarButtonItem position is incorrect - ios

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

Related

Change the title color of keyboard toolbar objective-C

I want to change the title color of keyboard toobar i.e(submit button), and the other is how can I add the image for keyboard toolbar. TIA
UIToolbar *keyboardToolbar = [[UIToolbar alloc] init];
[keyboardToolbar sizeToFit];
keyboardToolbar.translucent=NO; //if you want it.
keyboardToolbar.barTintColor = [UIColor lightGrayColor];
_txtCommentView.inputAccessoryView = keyboardToolbar;
keyboardToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:#"Submit" style:UIBarButtonItemStyleBordered target:self action:#selector(submitClicked:)],
nil];
Try below code and do changes as per your requirement:
UIToolbar *keyboardToolbar = [[UIToolbar alloc] init];
[keyboardToolbar sizeToFit];
keyboardToolbar.translucent=NO; //if you want it.
keyboardToolbar.barTintColor = [UIColor lightGrayColor];
_txtCommentView.inputAccessoryView = keyboardToolbar;
UIBarButtonItem *submit = [[UIBarButtonItem alloc] initWithTitle:#"Submit"
style:UIBarButtonItemStyleBordered
target:self action:#selector(submitClicked:)];
//Change submit button attributes here as you want
[submit setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"Helvetica-Bold" size:18.0], NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName,
nil] forState:UIControlStateNormal];
keyboardToolbar.items = [NSArray arrayWithObjects:submit, nil];
If you want to change the change in whole application Toolbar then Use
[UIToolbar appearance].tintColor = [UIColor redColor];
[UIToolbar appearance].barTintColor = [UIColor greenColor];
Also you can Use below code to change :
NSDictionary *attributes = #{
NSForegroundColorAttributeName: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0],
NSFontAttributeName: [UIFont fontWithName:#"Arial" size:16.0]
};
[[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];

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.

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

Navigation bar back button text is not changing

I am trying to change the text of the navigation bar back button text. I have tried the solutions offered here but I cant get the text I want on back button. In appdelegate I set these features:
[[UINavigationBar appearance] setBarTintColor:[self colorWithHexString:#"e74c3c"]];
[[UINavigationBar appearance] setBarTintColor:[self colorWithHexString:#"e74c3c"]];
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont fontWithName:#"Futura-CondensedMedium" size:19.0], UITextAttributeFont,nil]];
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowOffset = CGSizeMake(0.0, 1.0);
shadow.shadowColor = [UIColor whiteColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setTitleTextAttributes:
#{NSForegroundColorAttributeName:[UIColor whiteColor],
NSShadowAttributeName:shadow,
NSFontAttributeName:[UIFont fontWithName:#"Futura-CondensedMedium" size:19.0]
}
forState:UIControlStateNormal];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
And in every viewcontroller's viewdidload I set:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"SomeText" style:UIBarButtonItemStylePlain target:nil action:nil];
or
UIBarButtonItem *newBackButton =
[[UIBarButtonItem alloc] initWithTitle:#"NewTitle"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:newBackButton];
Any suggestions?
If I haven't misunderstood you you can do this to set the title of the back button. Suppose there are three view controllers: A, B and C. Now you want the title of the back button to be "MyViewA" when you navigate from A to B then you need to put this code in "viewWillAppear:" of your ViewController A (this will show the title of the back button as "MyViewA" when you are on view controller B).
//viewWillAppear of ViewController A
-(void)viewWillAppear:(BOOL)animated{
//now set title of back button
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:#"YourTitle"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
}
Likewise if you are navigating from B to C and want to set the back button title for ViewController C, you need to put the above code in "viewWillAppear:" delegate of ViewController B. In short you need to set the title of the next view controller on your current view controller.
You can't change the value of the text in the backbutton. You have to set the button as the left or right barButtonItem (probably left if you want it as back button) like this:
[self.navigationItem setLeftBarButtonItem:newBackButton];
you can then attach an IBAction to the button by setting it when you init your button:
UIBarButtonItem *newBackButton =
[[UIBarButtonItem alloc] initWithTitle:#"NewTitle"
style:UIBarButtonItemStyleBordered
target:nil
action:yourBackFunction];
at least that would be a workaround and I have also used it before...
The back button belongs to the previous view controller, not the one currently presented on screen.
To modify the back button you should update it before pushing, on the view controller that initiated the segue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Delete back item title in next controller
UIBarButtonItem *newBackButton =
[[UIBarButtonItem alloc] initWithTitle:#"New Title"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:newBackButton];
}

Change tint color on email dialog opened through ActivityView

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.

Resources