Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton shadow layer effect

I am creating a UIButton similar to this image: enter image description here

I tried it by using following code:

+(void)createShadowOnView:(UIView *)view color:(UIColor *)color width:(CGFloat)width height:(CGFloat)height shadowOpacity:(CGFloat)shadowOpacity andShadowRadius:(CGFloat)radius{

    view.layer.masksToBounds = NO;
    view.layer.shadowColor = color.CGColor;
    view.layer.shadowOffset = CGSizeMake(width,height);
    view.layer.shadowOpacity = shadowOpacity;
    [view.layer setShadowRadius:radius];
}

I was able to achieve this:

enter image description here

I want shadow effect on Button to be kept only on bottom part.

How can I achieve desired effect.

like image 365
Akshay Sunderwani Avatar asked Mar 02 '16 02:03

Akshay Sunderwani


1 Answers

Maybe you should set view's backgroundcolor, so the title has no shadow, you can set view.layer.shadowOffset to change the shadow size.

UIButton *customBTn = [UIButton buttonWithType:UIButtonTypeCustom];
customBTn.backgroundColor = [UIColor whiteColor];
customBTn.frame = CGRectMake(100, 100, 200, 50);
[customBTn setTitle:@"Sign Up" forState:UIControlStateNormal];
[customBTn setTitleColor:[UIColor colorWithRed:1/255.0 green:168/255.0 blue:244/255.0 alpha:1.0] forState:UIControlStateNormal];
customBTn.layer.borderColor = [UIColor colorWithRed:1/255.0 green:168/255.0 blue:244/255.0 alpha:1.0].CGColor;
customBTn.layer.borderWidth = 2;
customBTn.layer.cornerRadius = 25;
customBTn.layer.shadowColor = [UIColor lightGrayColor].CGColor;
customBTn.layer.shadowOffset = CGSizeMake(0,8);
customBTn.layer.shadowOpacity = 0.9;
[self.view addSubview:customBTn];

Output :-

enter image description here

like image 185
dev_hybird Avatar answered Oct 03 '22 05:10

dev_hybird