对于应用程序,我必须创建一个填充渐变和背景图像的 UIButton
。一切都工作正常,直到我将操作系统从 iOS 5.1 升级到最近发布的 iOS 6。
以下是模拟器的两个屏幕截图:
嗯,第一个屏幕截图显示了我需要的(和所做的),您可以看到棕色背景和灰色辐射。
下面是具有相同按钮但运行 iOS 6 的屏幕截图。正如您所看到的,渐变消失了,UIButton
底部出现了一条奇怪的白色 strip 。
我已经查看了这是否是一个错误或其他问题,但我什么也没发现,也许这里有人遇到了同样的问题?这是我的渐变代码
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = btnCountry.bounds;
UIColor *colorTop = [UIColor colorWithRed:.992f green:.992f blue:.992f alpha:1];
UIColor *colorBot = [UIColor colorWithRed:.788f green:.769f blue:.745f alpha:1];
gradient.colors = [NSArray arrayWithObjects:(id)[colorTop CGColor], (id)[colorBot CGColor], nil];
gradient.borderColor = [UIColor colorWithRed:.545f green:.506f blue:.459f alpha:1].CGColor;
gradient.borderWidth = 1;
gradient.masksToBounds = YES;
gradient.cornerRadius = 11;
[[btnCountry layer] insertSublayer:gradient atIndex:0];
最佳答案
这在 ios6 中是一个非常奇怪的问题,我在像通常那样设置渐变时遇到了同样的问题:
[myButton.layer insertSublayer:gradient atIndex:0];
所以我尝试将底线更改为这个,这在 iOS 6 和较低版本的 IOS 中都运行得很好
[myButton.layer insertSublayer:gradient below:myButton.titleLabel.layer];
希望这会有所帮助
关于iphone - iOS6以来按钮背景和渐变的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12564738/