美文网首页
iOS View颜色渐变

iOS View颜色渐变

作者: 路边的风景呢 | 来源:发表于2019-12-30 11:23 被阅读0次

    这里只做记录,具体的逻辑可以去网上查看。

    UIButton * changeBtn =[UIButton buttonWithType:UIButtonTypeCustom];

        changeBtn.frame=CGRectMake(SCREEN_WIDTH-94,CGRectGetMaxY(self.msgImage.frame)-20,60,20);

        changeBtn.layer.cornerRadius=10;

        changeBtn.layer.masksToBounds=YES;

        [changeBtnaddTarget:self action:@selector(changeBtnClick) forControlEvents:UIControlEventTouchUpInside];

        CAGradientLayer* gradientLayer =  [CAGradientLayer layer];

        gradientLayer.frame=CGRectMake(0,0,120,34);

        gradientLayer.startPoint=CGPointMake(0.5,1.44);

        gradientLayer.endPoint=CGPointMake(0.5,0.01);

        gradientLayer.locations=@[@(0.1),@(1.0)];//渐变点

        [gradientLayersetColors:@[(id)RGBCOLOR(255,206,198).CGColor,(id)RGBCOLOR(246,109,97).CGColor]];

        [changeBtn.layeraddSublayer:gradientLayer];

        changeBtn.backgroundColor = [UIColor redColor];

        [changeBtnsetTitle:@"兑换" forState:UIControlStateNormal];

        changeBtn.titleLabel.font=FONT(14);

        [self.contentViewaddSubview:changeBtn];

    效果大概是这样的

    相关文章

      网友评论

          本文标题:iOS View颜色渐变

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