Abamazi
Abamazi

Reputation: 39

Setting the background for Navigation View Controller

I added the Navigation View Controller in storyboard and connected it to each ViewController.

I then created the class:

@interface NavigationViewController : UINavigationController

In the implementation I have the following code:

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:@"#F40116" alpha:1.0];
    self.navigationController.navigationBar.translucent = NO;
}

I tried to change background for navigationBar to Red in all ViewControllers - but background is still white. How can I make them all Red?

Upvotes: 1

Views: 464

Answers (3)

Ryniere Silva
Ryniere Silva

Reputation: 443

I guess you are trying to change the color of the navigationBar of the navigationController of your navigationController.

Try this:

- (void)viewDidLoad {
    [super viewDidLoad];
   self.navigationBar.barTintColor = [UIColor colorWithHex:@"#F40116" alpha:1.0];
   self.navigationBar.translucent = NO;
}

Upvotes: 2

BEN MESSAOUD Mahmoud
BEN MESSAOUD Mahmoud

Reputation: 736

Try to make all visual changes on viewWillAppear

- (void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
    self.navigationBar.tintColor = [UIColor redColor];
}

this should work for you.

Upvotes: 0

Matic1911
Matic1911

Reputation: 391

Please try this:

- (void)viewDidLoad {
[super viewDidLoad];

[self.navigationBar setBarTintColor:[UIColor redColor]];
}

Make sure you set UINavigationController class to your's custom controller.

enter image description here

Upvotes: 0

Related Questions