1

我确实使用CAGradientLayer过自定义 UIButton iOS 5,它对我来说很好,并且获得自定义按钮也是一样的,当我在其中使用相同的代码时,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];
4

0 回答 0