Reputation: 7022
I have a Gradient that has three colors, Black, clear, and black. How would you increase the middle section?
The desired effect I am going for is a shading/gradient at the top, clear middle show content can show clearly, and a shading/gradient at the bottom. This is what I have so far.
How would I increase the middle portion of the gradient? I hope its clear. Here is my code too;
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor],(id)[[UIColor clearColor]CGColor],(id)[[UIColor blackColor] CGColor],nil];
[self.view.layer addSublayer:gradient];
Upvotes: 0
Views: 481
Reputation: 1053
The other answers' code in Swift:
gradient.locations = [0.2, 0.8, 1.0]
Upvotes: 0
Reputation: 332
Try QuartzCode to create gradient using GUI, should have things that you need www.quartzcodeapp.com
Upvotes: 0
Reputation: 1627
You should use CAGradientLayer's location property:
An optional array of NSNumber objects defining the location of each gradient stop. Animatable.
The gradient stops are specified as values between 0 and 1. The values must be monotonically increasing. If nil, the stops are spread uniformly across the range. Defaults to nil.
gradient.locations = @[@0.3, @0.7, @1.0];
Upvotes: 2
Reputation: 1471
Try playing with gradient.locations
gradient.locations = @[@(0.2), @(0.8), @(1.0)];
Upvotes: 2