美文网首页
UIButton 背景渐变色

UIButton 背景渐变色

作者: f79774d6d6bb | 来源:发表于2018-09-04 14:19 被阅读0次

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

    相关文章

      网友评论

          本文标题:UIButton 背景渐变色

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