0

I am trying to set gradient on my main View with custom colors. View is displayed completely white though. What's wrong with this record?

 CAGradientLayer *gradient = [CAGradientLayer new];

 gradient.colors = @[(id)[UIColor colorWithRed:92.0 green:196.0 blue:244.0 alpha:1].CGColor,
                    (id)[UIColor colorWithRed:47.0 green:146.0 blue:229.0 alpha:1].CGColor];
gradient.frame = self.backGroundView.bounds;
gradient.locations = @[@0.5, @0.5];

[self.backGroundView.layer insertSublayer:gradient atIndex:0];

This is properly displayed with blue and red cut in half of view's height.

CAGradientLayer *gradient = [CAGradientLayer new];
gradient.colors = @[(id)[UIColor redColor].CGColor, (id)[UIColor blueColor].CGColor];
gradient.frame = self.backGroundView.bounds;
gradient.locations = @[@0.5, @0.5];

[self.backGroundView.layer insertSublayer:gradient atIndex:0];

1 Answer 1

2

your colors are wrong. the UIColor initializer expects values between 0 and 1. try this:

gradient.colors = @[(id)[UIColor colorWithRed:92/255.0 green:196/255.0 blue:244/255.0 alpha:1].CGColor,
                    (id)[UIColor colorWithRed:47/255.0 green:146/255.0 blue:229/255.0 alpha:1].CGColor];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.