UIView*showView = [[UIViewalloc]initWithFrame:CGRectMake(100,100,100,100)];
[self.viewaddSubview:showView];
showView.backgroundColor= [UIColorredColor];
showView.alpha=0.5;
//创建一个gradientLayer
CAGradientLayer*gradientLayer = [CAGradientLayerlayer];
gradientLayer.frame= showView.bounds;
[gradientLayersetColors:[NSArrayarrayWithObjects:
(id)[[UIColorredColor]CGColor],
(id)[[UIColoryellowColor]CGColor],nil]];
[gradientLayersetLocations:@[@0.5,@0.9,@1]];
[gradientLayersetStartPoint:CGPointMake(0.5,1)];
[gradientLayersetEndPoint:CGPointMake(0.5,0)];
[showView.layeraddSublayer:gradientLayer];
效果如下图: