渐变色

作者: _Jock羁 | 来源:发表于2018-03-13 11:07 被阅读6次
渐变色
- (void)viewDidLoad {  
    [super viewDidLoad];  
  
    _contentView = [UIView new];  
    _contentView.frame = CGRectMake(100, 100, 100, 100);  
    _contentView.backgroundColor = [UIColor redColor];  
    [self.view addSubview:_contentView];  
      
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];  
    gradientLayer.frame = self.contentView.bounds;  
    [self.contentView.layer addSublayer:gradientLayer];  
      
//    gradientLayer.colors = (__bridge NSArray * _Nullable)([UIColor blueColor].CGColor);  
//    gradientLayer.colors = (__bridge NSArray * _Nullable)([UIColor cyanColor].CGColor);  
      
    //渐变区域  
    gradientLayer.locations = @[[NSNumber numberWithFloat:0.3], [NSNumber numberWithFloat:0.8]];  
      
    gradientLayer.colors = @[(__bridge NSArray * _Nullable)([UIColor blueColor].CGColor), (__bridge NSArray * _Nullable)([UIColor redColor].CGColor)];  
      
//    gradientLayer.startPoint = CGPointMake(0, 0);  
    //最大值为 (1, 1),最小值为(0, 0)  
    gradientLayer.startPoint = CGPointMake(1, 0);  
    gradientLayer.endPoint = CGPointMake(1, 1);  
      
} 

相关文章

网友评论

      本文标题:渐变色

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