gpt4 book ai didi

ios - 如何在iOS UIButton中添加投影?

转载 作者:行者123 更新时间:2023-12-01 17:50:38 27 4
gpt4 key购买 nike

需要专家的帮助

我正在自定义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;

}

现在,我想将在Adobe Photoshop中看到的“投影”的属性应用于此图像,

如何使用Core Graphics或iOS库的任何Core Foundation这样做?

Adobe的阴影如下所示

enter image description here
谢谢

最佳答案

button.layer.shadowColor = [UIColor blackColor].CGColor;
button.layer.shadowOffset = CGSizeMake(5, 5);
button.layer.shadowRadius = 5;
button.layer.shadowOpacity = 0.5;

关于ios - 如何在iOS UIButton中添加投影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32330073/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com