Remove shadow from ViewController - ios

I show shadow using the following code.
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(317, 0, 1, self.navigationController.view.frame.size.height)];
self.navigationController.view.superview.layer.masksToBounds = NO;
self.navigationController.view.layer.shadowColor = [UIColor blackColor].CGColor;
self.navigationController.view.layer.shadowOffset = CGSizeMake(3, 0); /*Change value of X n Y as per your need of shadow to appear to like right bottom or left bottom or so on*/
self.navigationController.view.layer.shadowOpacity = 0.5f;
self.navigationController.view.layer.shadowPath = shadowPath.CGPath;
I want to remove this shadow.I have tried some thing but not working? Any help is appreciated.

try by replacing balckColor to clearColor and Opacity to 0.0
self.navigationController.view.layer.shadowColor = [UIColor clearColor].CGColor;
self.navigationController.view.layer.shadowOpacity = 0.0f;

can you not just set opacity to 0.0.
self.navigationController.view.layer.shadowOpacity = 0.0;
Thanks!!

Related

iOS Button with round corners and a shadow

I have searched and tried the various solutions but without success. What I would like is a button background with rounded corners and a shadow. I can make one or the other happen but not both at the same time. Any help would be very welcome.
viewDepositButton_.layer.cornerRadius = 5.0;
CAGradientLayer *viewLayer = [CAGradientLayer layer];
[viewLayer setColors:aloColors];
[viewLayer setFrame:viewDepositButton_.bounds];
[viewDepositButton_.layer insertSublayer:viewLayer atIndex:0];
viewDepositButton_.clipsToBounds = YES;
viewDepositButton_.layer.shadowColor = [UIColor colorWithRed:0.46 green:0.46 blue:0.46 alpha:1.0].CGColor;
viewDepositButton_.layer.shadowOpacity = 0.8;
viewDepositButton_.layer.shadowRadius = 8;
viewDepositButton_.layer.shadowOffset = CGSizeMake(8.0f, 8.0f);
viewDepositButton_.clipsToBounds = YES; or viewDepositButton_.layer.masksToBounds = YES; will clip everything outside your layer - including the shadow.
However you have few options:
Put your button under a parent view, which will have the same corner radius and the shadow you want, but will have clipsToBounds = NO. This way you'll have your button as a subview of a view which has the shadow.
Use an image for your button, which has the rounded corners and set your buttons clipsToBounds to NO
Hope this helps
I was able to get your code to work by the following and it looks fine. Make sure you call your methods in proper sequence.
viewDepositButton_.layer.cornerRadius = 5.0;
viewDepositButton_.layer.borderWidth = 1.0;
viewDepositButton_.layer.shadowColor = [UIColor colorWithRed:0.46 green:0.46 blue:0.46 alpha:1.0].CGColor;
viewDepositButton_.layer.shadowRadius = 8;
viewDepositButton_.layer.shadowOpacity = 0.8;
viewDepositButton_.layer.shadowOffset = CGSizeMake(8.0f, 8.0f);
CAGradientLayer *viewLayer = [CAGradientLayer layer];
[viewLayer setColors:aloColors];
[viewLayer setFrame:viewDepositButton_.bounds];
[viewDepositButton_.layer insertSublayer:viewLayer atIndex:0];
[viewDepositButton_ viewLayer];}
Here is my code for setting up a rounded corner button with shadow.
button.layer.cornerRadius = 15;
button.layer.shadowRadius = 2.0f;
button.layer.shadowColor = [UIColor lightGrayColor].CGColor;
button.layer.shadowOffset = CGSizeMake(-1.0f, 3.0f);
button.layer.shadowOpacity = 0.8f;
button.layer.masksToBounds = NO;
Overall, the code is pretty straightforward. Please comment if you have any question, concerns or bugs.

Applying shadow on uibutton Makes the button text blury

Here is my code to add a shadow on my uibutton which is created using a .XIB file
UIBezierPath *shadowPathEndbtn = [UIBezierPath bezierPathWithRect:CGRectMake(0, self->_navigationView.frame.size.height - 70,[UIScreen mainScreen].bounds.size.width , 2)];
self->_EndButton.layer.masksToBounds = NO;
self->_EndButton.layer.shadowColor = [UIColor blackColor].CGColor;
self->_EndButton.layer.shadowOffset = CGSizeMake(0.0f, 5.0f);
self->_EndButton.layer.shadowOpacity = 0.7f;
self->_EndButton.layer.shouldRasterize = YES;
self->_EndButton.layer.shadowPath = shadowPathForEndbtn.CGPath;
I am able to set the shadow using this code but this code makes my button text look blury. I am unable to figure out the exact reason behind this. Any help is Appreciated!
self->_EndButton.layer.masksToBounds = false
self->_EndButton.layer.shadowColor = [UIColor blackColor].CGColor
self->_EndButton.layer.contentsScale = [[UIScreen mainScreen]scale];
self->_EndButton.layer.shadowOpacity = 0.7f;
self->_EndButton.layer.shadowRadius = 10.0;
self->_EndButton.layer.shadowOffset = CGSizeMake(0,0)
This will give shadow and also the test is not blurry
Set button background color
self.EndButton.BackgroundColor=[UIColor WhiteColor];

Shadow effects on ImageView in iOS

I am trying to provide a shadow effect to my Imageview just like in this image.
but the problem which I am facing it is that the shadow is actually visible from the bottom of the Imageview.
Here is the code which I have done to add the shadow. The color and all is still not matching with this one.
CAGradientLayer *shadow = [CAGradientLayer layer];
shadow.frame = CGRectMake(-100, 70, perspectiveView.frame.size.width,
perspectiveView.frame.size.height - 20);
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];
shadow.opacity = 1.0f;
[perspectiveView.layer addSublayer:shadow];
Please provide inputs. Also if the approach is wrong, feel free to guide me to any other approach.
Thanks in advance.
Also can anyone suggest how to provide a 3D border just like in the image which provides a slight width to the image view?
Perhaps, adding a shadow to the layer seems to work. You may want to try something like this:
// perspectiveView.transform = CGAffineTransformMakeRotation(-50.0f);
perspectiveView.layer.shadowOffset = CGSizeMake(10, 10);
perspectiveView.layer.shadowRadius = 5.0;
perspectiveView.layer.shadowOpacity = 0.6;
perspectiveView.layer.masksToBounds = NO;
You will need to playaround with these values to match your requirements. Hope this helps.
Here is my output:
Try this,
- (void)setShadow {
[perspectiveView.layer setShadowOffset:CGSizeMake(-5.0, 5.0)];
[perspectiveView.layer setShadowRadius:5.0];
[perspectiveView.layer setShadowOpacity:1.0];
}
you can use CALayer class , the layer can manage your visual aspects like background color, border, shadow and with it you can also manage the geometry of it content like size , transform etc .
visual effect(shadowing)
self.yourView.layer.shadowOffset = CGSizeMake(0, 3);
self.yourView.layer.shadowRadius = 5.0;
self.yourView.layer.shadowColor = [UIColor blackColor].CGColor;
self.yourView.layer.shadowOpacity = 1;
and you also used it for like self.yourView.layer.frame(Geometry)
more info https://developer.apple.com/library/ios/documentation/graphicsimaging/reference/CALayer_class/index.html
Below code work i have checked properly.
but Shikhar varshney can u check setShadow method call and perspectiveView is not nil.
- (void)setShadow {
perspectiveView.layer.shadowColor = [UIColor colorWithWhite:0.0
alpha:0.4f] CGColor;
perspectiveView.layer.shadowOffset = CGSizeMake(0, 1);
perspectiveView.layer.shadowOpacity = 1;
perspectiveView.layer.shadowRadius = 1.0;
perspectiveView.clipsToBounds = NO;
}

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.
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:
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.
In Swift 3, CGSizeMake no longer exists. It has been changed to CGSize(width: 20, height: 10). So the shadowOffset can be set like this in Swift 3:
myView.layer.shadowOffset = CGSize(width: 20, height: 10)
I found out that these values give a nice result :
myView.layer.shadowColor = UIColor.black.cgColor
myView.layer.shadowOpacity = 0.25
myView.layer.shadowRadius = 3
myView.layer.shadowOffset = CGSize(width: 1, height: 1) // shadow on the bottom right
I think your shadow offset is incorrect. It should be { 10 , 10} like:
[layer setShadowOffset:CGSizeMake( 10 , 10 ) ];

iOS Label Shadowing

I have this code here,
label.layer.shadowColor = [UIColor orangeColor].CGColor;
label.layer.shadowOffset = CGSizeMake(0,1);
label.layer.shadowRadius = 3.0;
label.layer.shadowOpacity = 0.5;
label.layer.shadowPath = [[UIBezierPath bezierPathWithRoundedRect:label.frame cornerRadius:20]CGPath];
I am using orange for testing purposes. Why is this not appearing as a shadow? All I am seeing is this, http://img12.imageshack.us/img12/1568/screenshot20130312at415.png
I am trying to get the gray label on the inside to have a shadow around the edges... Any help?
-Henry
You need to use label.bounds, not label.frame, to create the path. Also, make sure label.clipsToBounds is NO.
Try setting shadowOffset -1
label.layer.shadowOpacity = 1.0;
label.layer.shadowRadius =2.0;
label.layer.shadowColor = [UIColor blackColor].CGColor;
label.layer.shadowOffset = CGSizeMake(0.01,-1.0);
Also set label.bounds instead of label.frame
label.layer.shadowPath = [[UIBezierPath bezierPathWithRoundedRect:label.bounds cornerRadius:20]CGPath];

Resources