渐变view

  UIView * backView = [[UIView alloc] init];
        [self.view addSubview:backView];
    
        [backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left).offset(0);
            make.top.equalTo(self.view.mas_top).offset(RESIZE(0));
            make.width.mas_equalTo(SCREEN_WIDTH);
            make.height.mas_equalTo(RESIZE(150));
        }];
        backView.layer.masksToBounds = YES;
    
        //设置开始和结束位置(设置渐变的方向)
        CAGradientLayer * gradient= [CAGradientLayer layer];
        gradient.startPoint = CGPointMake(0, 0);
    
        gradient.endPoint = CGPointMake(0, 1);
    
        gradient.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithRed:0.50 green:0.74 blue:0.98 alpha:1.00].CGColor, [UIColor colorWithRed:0.45 green:0.57 blue:0.91 alpha:1.00].CGColor,[UIColor colorWithRed:0.36 green:0.35 blue:0.83 alpha:1.00].CGColor, nil];
    
        gradient.frame = CGRectMake(0, 0, SCREEN_WIDTH, RESIZE(150));
    
        [backView.layer insertSublayer:gradient atIndex:0];
    

你可能感兴趣的:(渐变view)