UIButton *thirdBtn = [UIButton buttonWithType:UIButtonTypeCustom];
thirdBtn.frame = CGRectMake(10, 50, 200, 44);
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(0, 0, 200, 44);
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1, 0);
gradientLayer.locations = @[@(0.5),@(1.0)];//渐变点
[gradientLayer setColors:@[(id)[[UIColor redColor] CGColor],(id)[RGB(100, 100, 100) CGColor]]];//渐变数组
[thirdBtn.layer addSublayer:gradientLayer];
[thirdBtn setTitle:@"代码创建的按钮,使用layer" forState:UIControlStateNormal];
[self.view addSubview:thirdBtn];
网友评论