Stronger shadow on iOS - ios

I am trying to animate a button with some glow effect.
So far this is what I got:
self.glowLayer = [[CALayer alloc] init];
self.glowLayer.contents = (__bridge id _Nullable)(self.currentBackgroundImage.CGImage);
self.glowLayer.opacity = 0; // set to 1 with animation.
self.glowLayer.shadowColor = [UIColor vtoPinkColor].CGColor;
self.glowLayer.shadowOffset = CGSizeZero;
self.glowLayer.shadowRadius = 5;
self.glowLayer.shadowOpacity = 1;
self.glowLayer.rasterizationScale = [UIScreen mainScreen].scale;
self.glowLayer.shouldRasterize = YES;
[self.layer addSublayer:self.glowLayer];
However, I find the glow effect not strong enough.
Of course I can change the shadow radius to make it wider but it only makes the shadow "dilute" instead of getting stronger.
How should I proceed ?

changing the value of
self.glowLayer.shadowOpacity 1 will work for you.
and also try Translucent = No

Related

How to make Circle image like Instagram's story profile image

I want to create circle image like the one in Instagram's story profile image. It should has two circles, inner circle will be white, outer circle color will be self-color not gradient. I have tried that code but there is only one circle. How to add second circle to imageView layer ?
self.imageView.layer.cornerRadius = 30;
self.imageView.layer.borderWidth = 3;
self.imageView.layer.borderColor = [UIColor whiteColor].CGColor;
self.imageView.layer.masksToBounds = YES;
Could you help me?
Thanks :)
You can use this 3rd party library which provides multiple borders to an UIImageView.
And, If you want to do it by yourself, you can make UIImageView a subView of UIView. Then make the UIView round and set borderWidth and colour in it. Do the same for the UIImageView.
Here's an example:
Add your UIView and UIImageView like this.
Then add this code:
-(void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
_profileImage.layer.cornerRadius = 30;
_profileImage.layer.borderWidth = 3;
_profileImage.layer.borderColor = [UIColor whiteColor].CGColor;
_profileImage.layer.masksToBounds = YES;
_profileImage.clipsToBounds = true;
_profileImage.layer.cornerRadius = _profileImage.frame.size.height/2;
_superViewImage.clipsToBounds = true;
_superViewImage.layer.masksToBounds = true;
_superViewImage.layer.cornerRadius = _superViewImage.frame.size.height/2;
_superViewImage.layer.borderWidth = 0.5;
_superViewImage.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor greenColor]);
}
And result image will be this:
Set the colours you want for both borders.
Hope it helps. :)

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];

Remove shadow from ViewController

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!!

How to make semi-transparent button with shadow?

I have a UIButton, that needs to be white and 50% transparent. In the same time I need shadow. But shadow is a rectangle and it could be seen through button background. Is it possible to make something with that?
The code I have now:
self.WhiteBtn.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:0.9];
self.WhiteBtn.opaque = NO;
self.WhiteBtn.clipsToBounds = NO;
self.WhiteBtn.layer.shadowColor = [UIColor blackColor].CGColor;
self.WhiteBtn.layer.shadowOpacity = 0.5;
self.WhiteBtn.layer.shadowRadius = 5;
self.WhiteBtn.layer.shadowOffset = CGSizeMake(0,0);
There were 2 initial problems: the shape of the shadow (which was rectangular initially) and the button background color being blended with the shadow color. Also, the UIColor initializer accepts all the arguments in range [0.0, 1.0]. Finally, I made some more tweaks and got this (see both the code and a sample button below).
Code:
let shadowPathWidth: CGFloat = 1.0 // fine tune your shadow's width with this
let layerAndShadowRadius: CGFloat = 5.0 //and its radius with this
WhiteBtn.backgroundColor = UIColor(red:1, green:1, blue:1, alpha:0.9)
WhiteBtn.layer.cornerRadius = layerAndShadowRadius
WhiteBtn.layer.shadowPath = CGPathCreateCopyByStrokingPath(CGPathCreateWithRoundedRect(WhiteBtn.bounds, layerAndShadowRadius, layerAndShadowRadius, nil), nil, shadowPathWidth, CGLineCap.Round, CGLineJoin.Bevel, 0.0)
WhiteBtn.layer.shadowOpacity = 1.0;
WhiteBtn.layer.shadowOffset = CGSizeMake(0,0)
Sample button:

Resources