UIView 实现渐变色 CAGradientLayer

来源:互联网 发布:怎样延长淘宝收货时间 编辑:程序博客网 时间:2024/06/04 18:56
- (UIView *)sendView {
    if (_sendView == nil) {
        _sendView = [[UILabel alloc]init];
        _sendView.frame = CGRectMake(0, 0, KScreenWidth-40, kH(30));
        
        /**
         *  渐变设置
         */
        _sendView.layer.borderWidth = 1;
        _sendView.layer.cornerRadius = 4;
        _sendView.layer.masksToBounds = YES;
        _sendView.layer.borderColor = [[UIColor lightGrayColor] CGColor];
        _sendView.backgroundColor = [UIColor yellowColor];
        //阴影
        _sendView.layer.shadowColor = [[UIColor redColor] CGColor];
        _sendView.layer.shadowOffset = CGSizeMake(5.0f, 5.0f); //[水平偏移, 垂直偏移]
        _sendView.layer.shadowOpacity = 1.0f; // 0.0 ~ 1.0 的值
        _sendView.layer.shadowRadius = 10.0f; // 阴影发散的程度
        
        //渐变光泽
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.frame = _sendView.bounds;
        gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor]CGColor], (id)[[UIColor lightGrayColor] CGColor], nil]; // 由上到下由白色渐变为灰色
        [_sendView.layer insertSublayer:gradient atIndex:0];
        [self addSubview:_sendView];
        
    }
    return _sendView;
}

0 0