Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop a shadow to right and bottom of uiview

I have to drop a shadow to the right and bottom of uiview.Im doing this in interface builder.But I see the shadow dropped to top of it.Tried differnt sizes.but couldn't get it.

layer.masksToBound=No layer.shadowOpacity=0.15 layer.shadowRadius=2 layer.shadowOffSet={10,-10}   //Values being set in Interfacebuilder. 

Still this drops shadow at top.What should I do to get at bottom of view.

like image 771
Honey Avatar asked Apr 18 '14 07:04

Honey


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.


2 Answers

Try the following code, it might help you

    myView.layer.shadowColor = [UIColor purpleColor].CGColor;     myView.layer.shadowOffset = CGSizeMake(5, 5);     myView.layer.shadowOpacity = 1;     myView.layer.shadowRadius = 1.0;     myView.layer.maskToBounds = NO; 

I tested this code and it's working and output is:

enter image description here

like image 140
Nitin Gohel Avatar answered Oct 08 '22 19:10

Nitin Gohel


Hi I have used below code ,it will provide you with shadow you want.

 UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:_viewShadow.bounds]; _viewShadow.layer.masksToBounds = NO; _viewShadow.layer.shadowColor = [UIColor blackColor].CGColor; _viewShadow.layer.shadowOffset = CGSizeMake(10.0f, 5.0f);  /*Change value of X n Y as per your need of shadow to appear to like right bottom or left bottom or so on*/ _viewShadow.layer.shadowOpacity = 0.5f; _viewShadow.layer.shadowPath = shadowPath.CGPath; 

Also masksToBounds is imp as it disables the clipping of sublayers that extend further than the view's bounds. If you put it YES then you won't see shadow as it clips sublayer where else in NO it allow to extent layer.

like image 30
nikhil84 Avatar answered Oct 08 '22 18:10

nikhil84