iphone - iOS6以来按钮背景和渐变的变化

标签 iphone uibutton ios6 cagradientlayer

对于应用程序,我必须创建一个填充渐变和背景图像的 UIButton。一切都工作正常,直到我将操作系统从 iOS 5.1 升级到最近发布的 iOS 6。

以下是模拟器的两个屏幕截图:

screenshot with iOS 5.1

Screnshot with iO 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/

相关文章:

iphone - 无法将数据从 Data sqlite 预加载到我的核心数据

iphone - iPhone编程中UIButton的问题

ios - UIButton 不能横向工作

ios - 显示 UINavigationBar 不工作

iphone - 在 CATiledLayer 中预加载/预显示图 block ?

ios - 为什么第二部手机与设备配对后,CBCentralManager 会向第一部手机报告 "Peer removed pairing information"?

iphone - 是否可以缩短临时构建配置文件过期之前的时间?

ios - swift 3 : How to center align (vertically & horizontally) UIButton on UIView?

iphone - CGAffineTransform 反转 : singular matrix in UIImagePickerController with showsCameraControls = NO

ios - self.tableView 为零,与调用 numberOfSections TableView 的 uitableview 不同