Change color of navigation bar

How to change default navigation bar color by default?

Thanks.

+3
source share
3 answers

The class UINavigationBarhas a property UIColor *tintColorthat you can change in the code.

Alternatively, this property is also displayed in the InterfaceBuilder interface development tool.

+4
source

Assuming that you added the navigation bar programmatically and not in Interface Builder, just put this in your viewDidLoad method.

self.navigationController.navigationBar.tintColor = [UIColor grayColor];
+4
source

TintColor . .

, navigationBar - UINavigationController, "setValue: forKey:". 5 , AppStore.

UINavigationBar drawRect: . ,

@implementation CustomNavigationBar

- (void) drawRect:(CGRect)rect
{
    [super drawRect:rect];
    UIImage *backgroundImage = ImageFromColor(WANTED_COLOR);
    [backgroundImage drawInRect:rect];
}

, UINavigationController initWithRootViewController:

- (id) initWithRootViewController:(UIViewController *)rootViewController
{
    self = [super initWithRootViewController:rootViewController]; 
    if (self) 
    {
        CustomNavigationBar *navBar = [CustomNavigationBar new];
        [self setValue:navBar forKey:@"navigationBar"];
    }
    return self;
}

, UINavigationController swizzling initWithRootViewController:

P.S. AppStore - .

0

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


All Articles