美文网首页
UIview子类设置渐变色

UIview子类设置渐变色

作者: 靠北的北 | 来源:发表于2019-02-26 14:21 被阅读1次

UIview子类设置渐变色

// 前置backgroundColor需要设置为clearColor
_titleLabel.backgroundColor = [UIColor ClearColor];
// UIview子类设置渐变色
_titleLabel.backgroundColor = [UIColor clearColor];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = CGRectMake(0, 0, 375, 40);
gradient.colors = [NSArray arrayWithObjects:
            (id)[UIColor redColor].CGColor,
            (id)[UIColor blackColor].CGColor,
            (id)[UIColor yellowColor].CGColor, nil];
gradient.startPoint = CGPointMake(0.5, 0);
gradient.endPoint = CGPointMake(0.5, 1);
gradient.locations = @[@0.0, @0.5, @1.0];
[_titleLabel.layer addSublayer:gradient];

相关文章

网友评论

      本文标题:UIview子类设置渐变色

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