创建了一个带有渐变层的按钮:
//MyGradient creates and returns gradient layers
CAGradientLayer *gradient = [MyGradient blueGradient];
//MyButton is a subclassed UIButton which adds some attributes
MyButton *testButton = [MyButton buttonWithType:UIButtonTypeCustom];
testButton.frame = CGRectMake(10, 10, 150, 50);
[testButton addTarget:self action:@selector(testButton:) forControlEvents:UIControlEventTouchUpInside];
[gradient setFrame:testButton.bounds];
testButton.clipsToBounds = YES;
[testButton.layer insertSublayer:gradient atIndex:0];
[self.view addSubview:testButton];
按下时如何使图像突出显示?我找到了一些示例代码,它们继承了 UIButton 并覆盖了 drawRect: 方法。有没有更简单的方法让按钮突出显示?