christianroman / CRGradientNavigationBar

Custom UINavigationBar subclass which allows gradient coloured navigation bar on iOS 7.
MIT License
914 stars 116 forks source link

Gradient not showing – only the second color #4

Closed bahlo closed 5 years ago

bahlo commented 10 years ago

I set the class CRGradientNavigationBar to the NavigationBar in my Storyboard.

Then in my custom UINavigationController class I do this in the viewDidLoad:

UIColor *firstColor = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:255/255.0f alpha:1.0f];
UIColor *secondColor = [UIColor colorWithRed:255.0f/255.0f green:90.0f/255.0f blue:58.0f/255.0f alpha:1.0f];
NSArray *colors = [NSArray arrayWithObjects:firstColor, secondColor, nil];
[[CRGradientNavigationBar appearance] setBarTintGradientColors:colors];
[self.navigationBar setTranslucent:NO];

The bar changes it's color, but only to the second one provided.

Thanks in advance.

christianroman commented 10 years ago

I assume you are using an IBOutlet, the code should be something like this:


#import "ViewController.h"
#import "CRGradientNavigationBar.h"

@interface ViewController ()

@property (nonatomic, weak) IBOutlet CRGradientNavigationBar *navigationBar;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSArray *colors = [NSArray arrayWithObjects:(id)[UIColor redColor].CGColor, (id)[UIColor orangeColor].CGColor, nil];

    [self.navigationBar setBarTintGradientColors:colors];

}
bahlo commented 10 years ago

Thanks for your answer.

I'm not using an IBOutlet, I'm extending UINavigationController, so self.navigationBar already exists and already has the class CRGradientNavigationBar (via Storyboard).

bahlo commented 10 years ago

I have recently started from scratch with code-only and have exactly the same problem. I copy-pasted the full example from the README and it only takes the second color (same problem). And I tried different View- and NavigationControllers but no changes.

Maybe a few words about my environment help:

When I NSLog the navigationController.navigationBar, I get this output:

<CRGradientNavigationBar: 0x10972eab0; baseClass = UINavigationBar; frame = (-512 0; 1024 44); autoresize = W; gestureRecognizers = <NSArray: 0x109732c00>; layer = <CALayer: 0x10972e970>>

The thing, that I find really strange is: On any iPhone app it just works (and looks great, btw.).

christianroman commented 10 years ago

Sorry, I didn't have enough time to replicate this bug, I'll look into it, I promise. :)

bahlo commented 5 years ago

Your last comment did not age well, haha. Closing since it's no longer an issue for me.