Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shadow left and right of UIView

Hi i like to add an CALayer Shadow to an View where the shadow was left and right of the view the simplest way was:

someView.layer.shadowColor = [[UIColor blackColor] CGColor];
someView.layer.shadowOffset = CGSizeMake(0.0f,0.0f);
someView.layer.shadowOpacity = 1.0f;
someView.layer.shadowRadius = 10.0f;
someView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:someView.bounds] CGPath];

but i will add a bigger shadow as like a shadow when i increase the shadowRadius it do not look good. How i can make a shadow that looks good at left and right.

like image 803
Zeropointer Avatar asked Jan 08 '13 16:01

Zeropointer


People also ask

How do I add inner shadow to UIView with rounded corners?

Add subview with the same color which will be centered on the parent and will be with several pixels smaller. Like this you will have space from each side of the parent. On the parent turn on clipping subviews and add shadow to the inner view. Like this, you can have an inner shadow.

How do you give shadow to corner radius of view in Swift?

The Solution I opted to create an inner containerView pinned to the edges of the parent view . The shadow is applied to the parent view 's layer, while the rounded corners are applied to the containerView . Then, just add all content to the containerView and be on your way.


1 Answers

I think 10 is a pretty big shadow radius, try 3 or 4 instead, also opacity I usually use 0.7:

someView.layer.shadowColor = [[UIColor blackColor] CGColor];
someView.layer.shadowOffset = CGSizeMake(0.0f,0.0f);
someView.layer.shadowOpacity = 0.7f;
someView.layer.shadowRadius = 4.0f;

If you want the shadow only on left and right, then inset the rectangle on the top and bottom so the top and bottom shadow are hidden behind your view:

CGRect shadowRect = CGRectInset(someView.bounds, 0, 4);  // inset top/bottom
someView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:shadowRect] CGPath];

I'm not really sure if that's what you wanted.

like image 68
progrmr Avatar answered Oct 21 '22 04:10

progrmr