开发技术文章

iOS button 按钮 设置渐变或者layer之后无法展示文

2022-03-02  本文已影响0人  VickyLanLan

CAGradientLayer *gl = [CAGradientLayer layer];

 gl.frame = CGRectMake(0,0,100,24);

gl.startPoint = CGPointMake(0, 0);

  gl.endPoint = CGPointMake(1, 1);

  gl.colors = @[(__bridge id)[UIColor colorWithRed:0/255.0 green:168/255.0 blue:79/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:26/255.0 green:186/255.0 blue:74/255.0 alpha:1.0].CGColor];

gl.locations = @[@(0.0),@(1.0f)];

 [_continueStudyBtn.layer addSublayer:gl];

1.解决方法。背景放在最底层

   [_continueStudyBtn.layer insertSublayer:gl atIndex:0];

    [_continueStudyBtn bringSubviewToFront:_continueStudyBtn.imageView];

上一篇 下一篇

猜你喜欢

热点阅读