How to add drop shadow only for the right side?

2.1k views Asked by At

I am adding the drop shadow like this.

vwVertical=[[UIView alloc] init];
[vwVertical setBackgroundColor:[UIColor whiteColor]];
vwVertical.translatesAutoresizingMaskIntoConstraints = NO;
vwVertical.layer.shadowColor=[UIColor colorWithRed:32/255 green:59/255 blue:90/255 alpha:1.0].CGColor;
vwVertical.layer.shadowOffset=CGSizeMake(5, 0);
vwVertical.layer.shadowOpacity=0.12;
vwVertical.layer.shadowRadius=6.5;
[vwBlock addSubview:vwVertical];

But this is adding shadow 3 sides. How can I add just to right side. Please help me. Thanks

1

There are 1 answers

6
dirtydanee On

All you need to do is to inset the view's bounds on top - left - bottom, and use the shadow path.

vwVertical=[[UIView alloc] init];
// Create edge insets
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0, 10, 0, 0);
// Create rect with inset and view's bounds
CGRect shadowPathOnlyIncludingRight = UIEdgeInsetsInsetRect(vwVertical.bounds, contentInsets);
// Apply it on the layer's shadowPath property
vwVertical.layer.shadowPath = [UIBezierPath bezierPathWithRect:shadowPathOnlyIncludingRight].CGPath;

[vwVertical setBackgroundColor:[UIColor whiteColor]];
vwVertical.translatesAutoresizingMaskIntoConstraints = NO;
vwVertical.layer.shadowColor=[UIColor colorWithRed:32/255 green:59/255 blue:90/255 alpha:1.0].CGColor;
vwVertical.layer.shadowOffset=CGSizeMake(5, 0);
vwVertical.layer.shadowOpacity=0.12;
vwVertical.layer.shadowRadius=6.5;