If I have two UIColors, what\'s the best way to draw an even gradient between them over an arbitrarily-sized area?
I am guessing you would create a UIView subclass a
hi you can use following to to apply gradient on view
-(void)applyGradientEffecttoView:(UIView *)aView
{
// Create the colors
UIColor *darkOp = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0];
UIColor *lightOp =[UIColor colorWithRed:255.0f green:255.0f blue:255.0f alpha:0.0];
// Create the gradient
CAGradientLayer *gradient = [CAGradientLayer layer];
// Set colors
gradient.colors = [NSArray arrayWithObjects:
(id)lightOp.CGColor,
(id)darkOp.CGColor,
nil];
gradient.locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:0.5],
nil];
// Set bounds
gradient.frame = aView.bounds;
// Add the gradient to the view
[aView.layer insertSublayer:gradient atIndex:0];
}