1

Help of experts is needed

I am making UIButton custom, where I am cropping of background and showing on UIButton as below.

[self setBackgroundImage:[self getSingleColorImageForLinear:self.frame] forState:UIControlStateSelected];




 //Method to make take image
-(UIImage *)getSingleColorImageForLinear:(CGRect)frame{


    CGSize size = CGSizeMake(frame.size.width,frame.size.height);
    UIGraphicsBeginImageContextWithOptions(size, NO, 0);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();

    size_t gradientNumberOfLocations = 1;
    CGFloat gradientLocations[1] = { 0.0 };
    CGFloat gradientComponents[4] = { 0, 0, 0, 0.3, };

    CGGradientRef gradient = CGGradientCreateWithColorComponents (colorspace, gradientComponents, gradientLocations, gradientNumberOfLocations);

    CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, size.height), 0);


    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    CGGradientRelease(gradient);
    CGColorSpaceRelease(colorspace);
    UIGraphicsEndImageContext();

    return image;

}

Now I want to apply, the property of Drop Shadow, seen in Adobe Photoshop to this Image,

How can I do so using Core Graphics or any Core Foundation of iOS Library?

Drop Shadow of Adobe looks as below

enter image description here Thanks

Sam Shaikh
  • 1,596
  • 6
  • 29
  • 53

1 Answers1

5
button.layer.shadowColor = [UIColor blackColor].CGColor;
button.layer.shadowOffset = CGSizeMake(5, 5);
button.layer.shadowRadius = 5;
button.layer.shadowOpacity = 0.5;
Igor
  • 1,537
  • 10
  • 12
  • I think you must check adobe, we pass an angle where shadow will fall. No accepted answer. – Sam Shaikh Sep 01 '15 at 11:43
  • why not, you can draw shadow with any offset changing shadowOffset? – Igor Sep 01 '15 at 11:51
  • ShadowOffset is not angle to shadow but its where it will be placed. after creating a shadow, but in Adobe angle, it can be on half too, not all sides, – Sam Shaikh Sep 01 '15 at 12:13
  • one thing more, this shadow will create a shadow of Label Text, I want a shadow on UIImage, which is at background. Clear? – Sam Shaikh Sep 01 '15 at 12:19
  • than you can add shadow to the UIImage directly, like here http://stackoverflow.com/questions/2936443/create-new-uiimage-by-adding-shadow-to-existing-uiimage – Igor Sep 01 '15 at 12:29
  • I can better google. Here are many issues, well, I am sorry, can't accept your answer. – Sam Shaikh Sep 01 '15 at 12:35
  • Yes, it's many issues, including custom drawing, or you can find UIImageView in button.subviews and draw shadow, using imageView.layer. And some others. Maybe you should concretize accepting criterias in your question? – Igor Sep 01 '15 at 12:39