需要做一个类似这种的倒计时
![](https://img.haomeiwen.com/i3794267/2cb645846d4a4a8c.png)
这种不难,但是比较烦,因为要把时分秒都分开,写好多label来存放
倒计时还是通过计时器来实现
- (void)timerClick
{
self.currentTime -=1;
[self calculation];
if (self.currentTime==0) {
[self stopNow];
}
}
后来又考虑到有的需要显示天数,前面就又加了一个,并且用bool来区分是否显示
-(XSTimerTextView *)toptimerView{
if (!_toptimerView) {
_toptimerView=[XSTimerTextView new];
_toptimerView.calculationTime=3600*48+20;
_toptimerView.showDayBool=YES;//yes显示天数,no只显示小时
_toptimerView.numberBackgroudColor=[UIColor greenColor];
_toptimerView.sepBackgroupColor=[UIColor blueColor];
_toptimerView.labelColor=[UIColor blackColor];
_toptimerView.sepColor=[UIColor whiteColor];
_toptimerView.textFont=17;
_toptimerView.sepFont=15;
}
return _toptimerView;
}
![](https://img.haomeiwen.com/i3794267/98d99b7afa13cc38.png)
demo已经上传GitHub,需要的可以自行下载并且根据需求修改
https://github.com/xinsun001/XSTimerCardView
网友评论