仿解鎖UILabel漸變色之CAGradientLayer漸變

效果圖

函數代碼:? 有關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;

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容