CAGradientLayer无法在iOS 6中运行

时间:2013-01-19 10:58:46

标签: iphone ios uibutton quartz-core cagradientlayer

我确实使用CAGradientLayer来自定义iOS 5中的UIButton,它对我来说很好,同样的事情来获取自定义按钮,当我在iOS 6显示时使用相同的代码时我只按white颜色按钮.. <QuartzCore/QuartzCore.h>不支持iOS 6 .. 是什么原因导致它没有显示自定义按钮。 检查它在iOS 5

中运行的代码
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(pressed) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"START " forState:UIControlStateNormal];
button.frame = CGRectMake(62, 250, 196, 37);

[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
[button setBackgroundColor:[UIColor blackColor]];
[[button titleLabel] setFont:[UIFont fontWithName:@"Knewave" size:18.0f]];

// Draw a custom gradient
CAGradientLayer *btnGradient = [CAGradientLayer layer];
btnGradient.frame = button.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];
[button.layer insertSublayer:btnGradient atIndex:0];

// Round button corners
CALayer *btnLayer = [button layer];
[btnLayer setMasksToBounds:YES];
[btnLayer setCornerRadius:5.0f];

// Apply a 1 pixel, black border around Buy Button
[btnLayer setBorderWidth:1.0f];
[btnLayer setBorderColor:[[UIColor blackColor] CGColor]];

[self.view addSubview:button];

0 个答案:

没有答案