Gradient Color


UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,30)];


CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = myView.bounds;
gradient.colors = [NSArray arrayWithObjects:
     (id)[UIColor clearColor].CGColor,
     (id)[UIColor blackColor].CGColor,
     (id)[UIColor blackColor].CGColor,
     (id)[UIColor clearColor].CGColor,
     nil];
gradient.locations = [NSArray arrayWithObjects:
        [NSNumber numberWithFloat:0.0f],
        [NSNumber numberWithFloat:0.2f],
        [NSNumber numberWithFloat:0.8f],
        [NSNumber numberWithFloat:1.0f],
        nil];


//gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor clearColor] CGColor], nil];
[myView.layer insertSublayer:gradient atIndex:0];



To display the gradient from left to right:

[gradientLayer setStartPoint:CGPointMake(0.0, 0.5)];
[gradientLayer setEndPoint:CGPointMake(1.0, 0.5)];