美文网首页OC-开发案例收集
iOS Button圆角,阴影,渐变色

iOS Button圆角,阴影,渐变色

作者: 一亩三分甜 | 来源:发表于2019-01-15 10:43 被阅读103次

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;
}
Snip20190115_1.png

相关文章

网友评论

    本文标题:iOS Button圆角,阴影,渐变色

    本文链接:https://www.haomeiwen.com/subject/acmedqtx.html