UIView - CAGradientLayer
CAGradientLayer *layer = [[CAGradientLayer alloc] init]; layer.frame = self.bounds; //渐变转折点 layer.locations = @[@0, @0.25, @0.75, @1]; //渐变颜色,个数与locations一致 layer.colors = [NSArray arrayWithObjects:(id)[UIColor clearColor].CGColor, (id)[UIColor blackColor].CGColor, (id)[UIColor blackColor].CGColor, (id)[UIColor clearColor].CGColor, nil]; //起始位置和结束位置,控制渐变的变化方向 layer.startPoint = CGPointMake(0, 0.5); layer.endPoint = CGPointMake(1, 0.5); self.layer.mask = layer;