iphone - CAGradientLayer 的问题

标签 iphone ios

我正在使用代码

NSArray *buttons = [NSArray arrayWithObjects: self.rollBtn,nil];        
for(UIButton *btn in buttons)
{       
    btn.layer.shadowRadius = 3.0;
    btn.layer.shadowOffset = CGSizeMake(-2.0, -3.0);
    btn.layer.shadowOpacity = 0.5;
    btn.layer.shadowColor = [UIColor blackColor].CGColor;
    CAGradientLayer *btnGradient = [CAGradientLayer layer];
    btnGradient.frame = btn.bounds;
    btnGradient.colors = [NSArray arrayWithObjects:
                          (id)[[UIColor colorWithRed:102.0f / 255.0f green:102.0f / 255.0f blue:102.0f / 255.0f alpha:1.0f] CGColor],
                          (id)[[UIColor colorWithRed:51.0f / 255.0f green:51.0f / 255.0f blue:51.0f / 255.0f alpha:1.0f] CGColor],
                          nil];

    [btn.layer insertSublayer:btnGradient atIndex:0];            
}

但我得到的只是一个带有阴影的按钮。我已经链接了 quartz 核心库,我导入了它,我已经链接了按钮,我尝试了使用不同类型的按钮;我被难住了。 任何想法出了什么问题吗? 提前致谢。

最佳答案

我遇到了同样的问题。看来您正在为 iOS6 构建 as I do .我发现 iOS6 中引入的 Storyboard自动布局导致了此类问题。如果您不使用此功能,只需禁用它即可:

  1. 在 Xcode 中打开 Storyboard
  2. 打开 Storyboard的属性(带有属性的右侧 Pane )
  3. 取消选中“Interface Builder Document”部分中的“Use Autolayout”。

关于iphone - CAGradientLayer 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13107320/

相关文章:

iphone - 使用SFTP协议(protocol)从iPhone上传文件

iphone - loadNibNamed, View 向上移动?

iphone - 带有提示的导航栏出现在带有新 iOS7 SDK 的 View 上

ios - 从另一个 viewController 快速检测 - iOS swift

ios - 如何在 CFQuery TableViewController 中为 tableView 设置背景图片

ios - iOS应用程序版本更新如何收费

iphone - 位置管理器 :didEnterRegion: only getting called when moving from certain locations

iPhone 内存,该相信什么?

ios - Xcode 不会越过崩溃

ios - 使用 Swift 连续动画化 UIViews 数组