【发布时间】:2012-09-24 12:04:57
【问题描述】:
对于一个应用程序,我必须创建一个填充有渐变和背景图像的UIButton。一切正常,直到我将操作系统从 iOS 5.1 升级到最近发布的 iOS 6。
以下是模拟器的两张截图:
嗯,第一个屏幕截图显示了我需要(并且做了),你可以看到棕色背景和灰色辐射。
以下是具有相同按钮但运行 iOS 6 的屏幕截图。如您所见,渐变消失了,UIButton 的底部出现了一条奇怪的白色条带。
我查看了这是否是错误或什么,但我什么也没发现,也许这里有人遇到过同样的问题?这是我的渐变代码
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];
【问题讨论】:
-
我终于找到了一种方法,通过使用以下代码删除子视图来恢复按钮的“正常”外观:
for(UIView* subView in btnCountry.subviews) if([subView isKindOfClass:NSClassFromString(@"UIGroupTableViewCellBackground")]) [subView removeFromSuperview];但现在,当我点击按钮时,它会导致错误 EXC_BAD_ACC,没有人线索还是什么? -
这个question是相关的
标签: iphone uibutton ios6 cagradientlayer