iOS UIView设置渐变背景色

        CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
        gradientLayer.frame = CGRectMake(0, 0, imageView.frame.size.width, mainFrame.size.height / 2);
        gradientLayer.colors = @[(__bridge id)[UIColor colorWithHex:0x000000 alpha:0].CGColor, (__bridge id)[UIColor colorWithHex:0x000000 alpha:1].CGColor];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(0, 1);
        [backView.layer addSublayer:gradientLayer];

 

你可能感兴趣的:(iOS UIView设置渐变背景色)