My question is simple.
I want to use CAGradientLayer to make a nice gradient background for my UIView.
But the problem is that it displays an ugly violet color instead of my desired wonderful red color.
Here is the code I’m using :
- (void)viewWillAppear:(BOOL)animated {
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor blackColor] CGColor], (id)[[UIColor colorWithRed:107 green:0 blue:27 alpha:1] CGColor], nil];
[self.view.layer insertSublayer:gradient atIndex:0];
}
As a result, I can see that :

And that is not what I want… If someone can help me with this.
Thanks ! Cheers 🙂
You must use fractions, not whole numbers:
Of course, be wary of integer division. That bastard always gets me in these situations.