I want to implement alpha gradient on an image. From 0.5 alfa on top of the image to 0.0 on bottom. Any advice, tutorial, link is welcome.
You can try CAGradientLayer.
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)] autorelease];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
[view.layer insertSublayer:gradient atIndex:0];
Another option
Try the answer suggested by @Caleb in this previous SO question
You can go for Graphics Contexts. All drawing happens in a graphics context. If you want to create an image that has a radial gradient, or a linear gradient, or anything else, you'll need to:
- Create a graphics context for your image with
UIGraphicsBeginImageContextWithOptions.- Do whatever drawing you want to appear in the image.
- Call
UIGraphicsGetImageFromCurrentImageContextto get the image from the context.
This gives you aUIImage, so no need to convert from aCGImage.- Call
UIGraphicsEndImageContextto clean up the context.You can also have a look at Radial gradient on UImage