渐变色设置

2020-05-22  本文已影响0人  super_2e20
- (void)setBgView{
  NSArray <UIColor *> * colors = @[HEXRGBCOLOR(0xC8A75C),HEXRGBCOLOR(0xB58A36)];

  CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  gradientLayer.frame = CGRectMake(0, 0, SCREEN_WIDTH, NAVIGATIONBAR_HEIGHT);
  gradientLayer.startPoint = CGPointMake(0, 1);
 gradientLayer.endPoint = CGPointMake(1, 1);

 NSMutableArray *gradientColors = [NSMutableArray array];
  for (UIColor *colorItem in colors) {
    [gradientColors addObject:(id)colorItem.CGColor];
 }
 gradientLayer.colors = [NSArray arrayWithArray:gradientColors];
 UIGraphicsBeginImageContextWithOptions(gradientLayer.frame.size,    gradientLayer.opaque, 0);
   [gradientLayer renderInContext:UIGraphicsGetCurrentContext()];
 UIImage *outputImage =  UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 UIImageView *imageview = [[UIImageView alloc]init];
 imageview.frame = self.bgView.frame;
 imageview.image = outputImage;
 //    self.bottomView.layer.contents =(id) outputImage.CGImage;
   self.bgView.layer.contents = (id)outputImage.CGImage;

}
上一篇 下一篇

猜你喜欢

热点阅读