How to add shadow only to the bottom and right side of uiview?

I am thinking of adding shadows for the bottom and right sides of the UIView, but I found that all the solutions there added shadows for the four sides of the view. Is there any way around this?

+3
source share
3 answers

I can do this by adding two UIImageViews with a stretched shadow image on the bottom and right side of the view. You do not need to cover all views with these UIImageViews, you just clamp as much as you need. Take a look at the colored twitter layers on the iPhone, I believe that these beautiful shadows are created using UIImageViews. And it saves system resources. Of course, you can use CALayer to create the shadow, but I think it consumes more system resources to render the shadow, so CALayer is the second choice for me.

+1
source

You can use CAGradientLayerso

CAGradientLayer *shadow = [CAGradientLayer layer];
shadow.frame = CGRectMake(-10, 0, 10, myView.frame.size.height);
shadow.startPoint = CGPointMake(1.0, 0.5);
shadow.endPoint = CGPointMake(0, 0.5);
shadow.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:0.0 alpha:0.4f] CGColor], (id)[[UIColor clearColor] CGColor], nil];
[myView.layer addSublayer:shadow];

frame . . .

+19
UIBezierPath *shadowPath = [UIBezierPath 
bezierPathWithRect:self.yourViewObj.bounds];
self.yourViewObj.layer.masksToBounds = NO;
self.yourViewObj.layer.shadowColor = [UIColor blackColor].CGColor;//*** color you want for shadow
self.yourViewObj.layer.shadowOffset = CGSizeMake(5.0f, 5.0f);
self.yourViewObj.layer.shadowOpacity = 0.7f;
self.yourViewObj.layer.shadowPath = shadowPath.CGPath;
0
source

All Articles