iOS绘制渐变色

    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(100, 100, 100, 100);
    [self.view addSubview:button];
    CAGradientLayer * layar = [CAGradientLayer new];
    layar.colors = @[(__bridge id)[UIColor whiteColor].CGColor ,(__bridge id)[UIColor yellowColor].CGColor];
    layar.startPoint = CGPointMake(0, 0);
    layar.endPoint = CGPointMake(0, 1);
    layar.frame = button.frame;
    [button.layer addSublayer:layar];

你可能感兴趣的:(iOS绘制渐变色)