需要专家帮助
我正在制作UIButton自定义,我正在裁剪背景并在UIButton上显示如下。
[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;
}
现在我想申请Drop Shadow的属性,在Adobe Photoshop中看到此图片,
如何使用Core Graphics或任何iOS库的Core Foundation?
Adobe的阴影看起来如下
答案 0 :(得分:4)
button.layer.shadowColor = [UIColor blackColor].CGColor;
button.layer.shadowOffset = CGSizeMake(5, 5);
button.layer.shadowRadius = 5;
button.layer.shadowOpacity = 0.5;