gpt4 book ai didi

ios - 将 CALayer 放在 UIButton 层堆栈的最底部

转载 作者:行者123 更新时间:2023-11-29 02:46:00 25 4
gpt4 key购买 nike

这看起来很简单 - 也许你能帮我找到解决方案?

我为 UIButton 编写了一个自定义阴影。我试图将它放置在 UIButton 层堆栈的最低索引处。不幸的是,它没有放置在 UIButton 的其余部分下方。

代码:

//UIButton type custom
alarmSetterButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *img = [UIImage imageNamed:@"rootSchedulerButton"];

//Scaling
float delta = 2.4f;
if (IS_IPHONE_5) delta = 2.0f;

[alarmSetterButton setFrame:CGRectMake(0.0f, 0.0f, (img.size.width/delta), (img.size.height/delta))];
[alarmSetterButton setBackgroundImage:img forState:UIControlStateNormal];
[alarmSetterButton setTitle:@"" forState:UIControlStateNormal];
[alarmSetterButton addTarget:self action:@selector(setSecondaryView:) forControlEvents:UIControlEventTouchUpInside];

//the colors for the gradient
UIColor *high = [UIColor colorWithWhite:0.0f alpha:1.0f];
UIColor *low = [UIColor colorWithWhite:0.0f alpha:0.0f];

//The gradient, simply enough. It is a rectangle
CAGradientLayer * gradient = [CAGradientLayer layer];
[gradient setFrame:[b bounds]];
[gradient setColors:[NSArray arrayWithObjects:(id)[high CGColor], (id)[low CGColor], nil]];
[gradient setAnchorPoint:CGPointMake(0.5f, 0.0f)];
[gradient setTransform:CATransform3DMakeRotation(315.0 / 180.0 * M_PI, 0.0, 0.0, 1.0)];

// What needs altered
[alarmSetterButton.layer insertSublayer:gradient below:alarmSetterButton.layer];

最佳答案

我找到了解决方案。我没有使用 UIButton 的 setBackroundImage:forState: 方法,而是编写了一个新的 CALayer 来包含图像的内容。

感谢您的帮助。

:)

关于ios - 将 CALayer 放在 UIButton 层堆栈的最底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25128053/

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