CAGradientLayer * gradientLayer = [CAGradientLayer layer];
NSArray * colors = [NSArray arrayWithObjects:(id)[UIColor colorWithWhite:0 alpha:0].CGColor,(id)[UIColor colorWithWhite:1 alpha:1].CGColor,(id)[UIColor colorWithWhite:1 alpha:1].CGColor,(id)[UIColor colorWithWhite:0 alpha:0].CGColor, nil];
[gradientLayer setColors:colors];
[gradientLayer setStartPoint:CGPointMake(0, 0)];
[gradientLayer setEndPoint:CGPointMake(1.0, 0)];
gradientLayer.locations = @[@0,@0.10,@0.90,@1];
[gradientLayer setFrame:self.bounds];
[self.layer setMask:gradientLayer];
如上,设置两侧10%区域从透明到不透明的遮罩效果。