Navigation bar button color

I canโ€™t change the color of the navigation bar button. Any help? I have configured the UINavigationBar class, but I cannot change the color of the button back.

UINavigationBar class code

#import 
#import "UINavigationBar.h"

@interface UINavigationBar (Category)
{

}

.m file code

- (void) drawRect: (CGRect) rect 
{

    [[UIImage imageNamed: @ "top.png"] drawInRect: rect];
    self.tintColor = [UIColor colorWithRed: 38 green: 65 blue: 82 alpha: 1];    
}

I cannot change the color of the back button.

+3
source share
5 answers

With this, you can change the color of all navigation buttons:

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

Replace redColor as follows to adjust the color of the buttons:

colorWithRed:0/255.0 green:144/255.0 blue:200/255.0 alpha:1.0// pick your color using this.

Note. Available for iOS 5 and>

+9
source

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed: 127.0/255.0f green:127.0/255.0f blue:127.0/255.0f alpha:1.0];
+2

You need to use UIBarButtonItem with a custom view. Something like that:

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
[button addTarget:target action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"back_button.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"back_button_tap.png"] forState:UIControlStateHighlighted];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

Then you can put the button in the navigation bar, usually in the controller with the UINavigationController:

self.navigationItem.leftBarButtonItem = buttonItem;
+1
source

In iOS7 you have to replace the button color with

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
0
source

In swift and iOs 7 and 8, write this:

 self.navigationController.navigationBar.tintColor = UIColor.whiteColor() //<-- whiteColor is an example!!
0
source

Source: https://habr.com/ru/post/1792226/


All Articles