美文网首页
仿解锁UILabel渐变色之CAGradientLayer渐变

仿解锁UILabel渐变色之CAGradientLayer渐变

作者: 萧过 | 来源:发表于2016-08-08 14:19 被阅读0次
    效果图

    函数代码:  有关CAGradientLayer知识见上篇文章

    #pragma mark 字体动画  解锁

    -(void)lableAnmation

    {

    self.backgroundColor=[UIColor grayColor];

    CAGradientLayer *theGtradient=[CAGradientLayer layer];

    theGtradient.frame=CGRectMake(0, 200, CGRectGetWidth(self.frame), 66);

    [self.layer addSublayer:theGtradient];

    theGtradient.colors=@[

    (__bridge id)[UIColor blackColor].CGColor,

    (__bridge id)[UIColor whiteColor].CGColor,

    (__bridge id)[UIColor blackColor].CGColor

    ];

    theGtradient.locations=@[@.25,@.5,@.75];

    theGtradient.startPoint=CGPointMake(0, 0.5);

    theGtradient.endPoint=CGPointMake(1., 0.5);

    //动画

    CABasicAnimation *theAnima=[CABasicAnimation animationWithKeyPath:@"locations"];

    theAnima.fromValue=@[@0,@0,@0.25];

    theAnima.toValue=@[@0.25,@1,@1];

    theAnima.duration=2.5;

    theAnima.repeatCount=HUGE;

    [theGtradient addAnimation:theAnima forKey:@"locations"];

    //uilable文字

    UILabel *theUnlock=[[UILabel alloc]initWithFrame:theGtradient.bounds];

    [self addSubview:theUnlock];

    theUnlock.alpha=.5;

    theUnlock.text=@"滑动解锁 >>";

    theUnlock.textAlignment=NSTextAlignmentCenter;

    theUnlock.font=[UIFont boldSystemFontOfSize:30];

    theGtradient.mask=theUnlock.layer;

    }

    相关文章

      网友评论

          本文标题:仿解锁UILabel渐变色之CAGradientLayer渐变

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