iOS给按钮增加阴影,圆角,渐变色。
-(UIButton *)checkBtn
{
if (!_checkBtn) {
//阴影
_checkBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_checkBtn setTitle:@"知道了,立即验证" forState:UIControlStateNormal];
[_checkBtn setTitleColor:kHexColor(0xffffff) forState:UIControlStateNormal];
[_checkBtn addTarget:self action:@selector(onCheck:) forControlEvents:UIControlEventTouchUpInside];
_checkBtn.layer.shadowColor = [UIColor colorWithRed:247/255.0 green:174/255.0 blue:5/255.0 alpha:0.30].CGColor;
_checkBtn.layer.shadowOffset = CGSizeMake(0, 5);
_checkBtn.layer.shadowOpacity = 1;
_checkBtn.layer.shadowRadius = 5;
//渐变色,圆角
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = @[(__bridge id)kHexColor(0xF6AB00).CGColor,(__bridge id)kHexColor(0xF98F33).CGColor];
gradientLayer.locations = @[@0.0,@1.0];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1.0, 0);
gradientLayer.frame = CGRectMake(0, 0, kUnitWidth(285), kUnitHeight(45));
gradientLayer.cornerRadius = kUnitHeight(22.5);
[_checkBtn.layer addSublayer:gradientLayer];
}
return _checkBtn;
}