I need to add mask on top and buttom of the screen like this.
How can I achieve this ?
if (!UIAccessibilityIsReduceTransparencyEnabled()) {
self.BlurView.backgroundColor = [UIColor clearColor];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = self.view.bounds;
[blurEffectView setAlpha:1.0];
[self.BlurView addSubview:blurEffectView];
}
Where self.BlurView
is type of UIView
.
You can keep this for your upper and bottom view . And can adjust frame blurEffectView.frame
according to your upper and bottom dimensions .
Hope this will help you.
Add UIVisualEffectView over the top:
UIVisualEffectView * vs = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
vs.frame = self.view.bounds;
[self.view addSubview:vs];
Add this code:
CAGradientLayer * layer = [CAGradientLayer layer];
layer.frame = tableHolder.bounds;
layer.colors = [NSArray arrayWithObjects:(id)[UIColor blackColor].CGColor, (id)[UIColor clearColor].CGColor, (id)[UIColor clearColor].CGColor, nil];
layer.locations = @[@0.90,@0.99,@1.0];
layer.startPoint = CGPointMake(0.0, 1.0f);
layer.endPoint = CGPointMake(0.0f, 0.0f);
tableHolder.layer.mask = layer;
tableHolder.layer.masksToBounds = true;
[tableHolder.layer insertSublayer:layer atIndex:0];
Adjust the variables for your own needs, you'll have to change the locations.
You're not 'blurring' the tops and bottoms, but gradually masking them out via the gradient layer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With