有人可以为我无聊的UIButton添加渐变吗?



我正在努力使渐变层与我的按钮对齐。 我希望有人能很快帮助我,这样我的按钮就不会那么bjaaah了。

这是我正在使用的内容:

UIButton *tmpBtn = [[UIButton alloc] initWithFrame:theFrame];
[tmpBtn setTintColor:buttonColor];
[tmpBtn setBackgroundColor:buttonColor];
tmpBtn.layer.cornerRadius = 10;
tmpBtn.layer.borderWidth = 1;
tmpBtn.layer.borderColor = [UIColor blackColor].CGColor;

(按钮颜色正在传递到方法中,它现在只是一种颜色(

感谢您的任何帮助!

向按钮添加渐变

 CAGradientLayer *gradientLayer = [CAGradientLayer layer];
 gradientLayer.frame = yourButton.layer.bounds;
 gradientLayer.cornerRadius =yourButton.layer.cornerRadius;
 [yourButton.layer addSublayer:gradientLayer];

最新更新