Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get shadow in UIButton inside

Using below code for shadow in outside for UIButton. But how can i get shadow for inside the button

button.imageView.layer.cornerRadius = 7.0f;
button.layer.shadowRadius = 3.0f;
button.layer.shadowColor = [UIColor blackColor].CGColor;
button.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
button.layer.shadowOpacity = 0.5f;
button.layer.masksToBounds = NO;
like image 496
vikramarkaios Avatar asked Feb 09 '16 12:02

vikramarkaios


2 Answers

   #define kDEFAULT_SHADOW_COLOR [UIColor lightGrayColor]   
   UIColor *color = [kDEFAULT_SHADOW_COLOR colorWithAlphaComponent:0.3f];
        NSArray *colorsArray = @[(id)[color CGColor], (id)[[UIColor clearColor] CGColor]];
        CGFloat yOffset = 0.0f;
        CGFloat leftHeight = button.bounds.size.height;
        CAGradientLayer *shadow;
        shadow = [CAGradientLayer layer];
        shadow.colors = colorsArray;
        shadow.frame = CGRectMake(0, yOffset, 5.0, leftHeight);
        shadow.startPoint = CGPointMake(0.0, 0.5);
        shadow.endPoint = CGPointMake(1.0, 0.5);
        [button.layer insertSublayer:shadow atIndex:0];
like image 180
vikramarkaios Avatar answered Oct 10 '22 07:10

vikramarkaios


You have not implemented the button shadows property. Add the following lines of code and show shadow. The Code is...

self.submitBtn.layer.masksToBounds = YES;
self.submitBtn.layer.clipsToBounds = YES;
like image 20
Sucharu Hasija Avatar answered Oct 10 '22 06:10

Sucharu Hasija