Shan Shan - 7 months ago 18
iOS Question

How to make this kind of effect in iOS, blur effect it is increasing leaner to lower side

I am searched for this, but i didn't found the exact solution for my problem, all the answer for making blur effect shows making the blur effect on entire frame but i want the blur effect something look like below image

enter image description here

in the image the blur effect is at the bottom that to, it is increasing leaner to lower side

can any one know how to do this, any ideas or sample code for this ... :)


Use CAGradientLayer

UIColor *theColor = [[UIColor alloc] initWithRed:146.0/255.0 green:146.0/255.0 blue:146.0/255.0 alpha:1];

CAGradientLayer *gradientLayer = [CAGradientLayer layer];

CGRect gradientLayerFrame = theView.frame;
gradientLayerFrame.origin.x = 0;
gradientLayerFrame.origin.y = 0;
gradientLayer.frame = gradientLayerFrame;

//build the colors array for the gradient
NSArray *colors = [NSArray arrayWithObjects:
                   (id)[theColor CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.9f] CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.6f] CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.4f] CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.3f] CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.1f] CGColor],
                   (id)[[UIColor clearColor] CGColor],

gradientLayer.colors = colors;

[yourView.layer insertSublayer:gradientLayer atIndex:0];

swift version of this code is hear