0
votes

I am having two controller with different navigation bar color. let say I want to set first controller with navigation bar black color and TitleTextAttributes color whiteColor and after navigate to second controller it change navigation bar white color and TitleTextAttributes black color. navigation bar color change but title text attribute is not changing. Please suggest.

i write this code and used in viewWillAppear method.

Inside navigation bar category

typedef NS_ENUM( NSUInteger, UINavigationBarColor) {
    White,
    Black
};

+(void)setNavigationColor:(UINavigationBarColor)color{
    if (color == White) {
         [[self appearance] setTintColor:[UIColor whiteColor]];
        NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor blackColor]};
        [[self appearance] setTitleTextAttributes:attributes];
    } else {
        [[self appearance] setTintColor:[UIColor blackColor]];
        NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
        [[self appearance] setTitleTextAttributes:attributes];
    }
}
1

1 Answers

0
votes

Your code is setting the tintColor and titleTextAttributes on UINavgiationBar appearance. That only affects newly created navigation bars. It does not change any existing navigation bars.

You need to make setNavigationColor an instance method and change [self appearance] to just self.