我有一个UIButton,我想在图像(带透明背景的符号)下方设置渐变作为背景,但我遇到了两个不同的问题。
首先,无论我如何尝试添加它,CAGradientLayer似乎都会覆盖在图像之上,完全遮挡了图像。
其次,渐变本身似乎被强烈加深,就像按钮被禁用一样,但实际上并没有被禁用。
这是我的代码:
首先,无论我如何尝试添加它,CAGradientLayer似乎都会覆盖在图像之上,完全遮挡了图像。
其次,渐变本身似乎被强烈加深,就像按钮被禁用一样,但实际上并没有被禁用。
这是我的代码:
self.backButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 35, 28, 28)];
[backButton addTarget:self
action:@selector(goBack)
forControlEvents:UIControlEventTouchUpInside];
[backButton setBackgroundColor:[UIColor clearColor]];
CAGradientLayer *buttonGradient = [CAGradientLayer layer];
buttonGradient.frame = backButton.bounds;
buttonGradient.colors = [NSArray arrayWithObjects:
(id)[[UIColor colorWithRed:.0
green:.166
blue:.255
alpha:1] CGColor],
(id)[[UIColor colorWithRed:.0
green:.113
blue:.255
alpha:1] CGColor],
nil];
[buttonGradient setCornerRadius:backButton.frame.size.width / 2];
[backButton.layer insertSublayer:buttonGradient
atIndex:0];
[backButton setImage:[UIImage imageNamed:@"backarrow.png"]
forState:UIControlStateNormal];
[backButton setEnabled:NO];
[topbarView addSubview:backButton];