UIButton 背景渐变色

2018-09-04  本文已影响0人  f79774d6d6bb

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];

上一篇下一篇

猜你喜欢

热点阅读