Believe in your own future, will thank yourself right now Sinner Yun

Sinner_Yun

蒙版渐变的实现

 

 

要求整个view渐渐alpha变透明,包括view上的子view,需要一起变透明。

 

-(void)testAlpha{     
    [self.view layoutIfNeeded];     
    UIColor *color1 = [UIColor colorWithRed:(0)  green:(0)  blue:(0)   alpha:1.0];     
    UIColor *color2 = [UIColor colorWithRed:(0)  green:(0)  blue:(0)  alpha:0.8];     
    UIColor *color3 = [UIColor colorWithRed:(0)  green:(0)  blue:(0)  alpha:0.2];     
    NSArray *colors = [NSArray arrayWithObjects:(id)color1.CGColor, color2.CGColor,color3.CGColor, nil];     
    NSArray *locations = [NSArray arrayWithObjects:@(0.0), @(0.7),@(1.0), nil];     
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];     
    gradientLayer.colors = colors;     
    gradientLayer.locations = locations;     
    gradientLayer.frame = _inputView.bounds;     
    gradientLayer.startPoint = CGPointMake(0, 0);     
    gradientLayer.endPoint   = CGPointMake(1, 0);     
    _inputView.layer.mask = gradientLayer; 
}

 

posted on 2016-10-21 11:25  Sinner_Yun  阅读(467)  评论(0编辑  收藏  举报

导航