How to make this kind of effect in iOS, blur effect it is increasing leaner to lower side

后端 未结 1 353
半阙折子戏
半阙折子戏 2021-01-16 15:52

I am searched for this, but i didn\'t found the exact solution for my problem, all the answer for making blur effect shows making the blur effect on entire frame but i want

相关标签:
1条回答
  • 2021-01-16 16:10

    Use CAGradientLayer

    UIColor *theColor = [[UIColor alloc] initWithRed:146.0/255.0 green:146.0/255.0 blue:146.0/255.0 alpha:1];
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    
    CGRect gradientLayerFrame = theView.frame;
    gradientLayerFrame.origin.x = 0;
    gradientLayerFrame.origin.y = 0;
    gradientLayer.frame = gradientLayerFrame;
    
    //build the colors array for the gradient
    NSArray *colors = [NSArray arrayWithObjects:
                       (id)[theColor CGColor],
                       (id)[[theColor colorWithAlphaComponent:0.9f] CGColor],
                       (id)[[theColor colorWithAlphaComponent:0.6f] CGColor],
                       (id)[[theColor colorWithAlphaComponent:0.4f] CGColor],
                       (id)[[theColor colorWithAlphaComponent:0.3f] CGColor],
                       (id)[[theColor colorWithAlphaComponent:0.1f] CGColor],
                       (id)[[UIColor clearColor] CGColor],
                       nil];
    
    gradientLayer.colors = colors;
    
    [yourView.layer insertSublayer:gradientLayer atIndex:0];
    

    swift version of this code is here

    0 讨论(0)
提交回复
热议问题