All Projects → SmileZXLee → ZXCountDownView

SmileZXLee / ZXCountDownView

Licence: MIT License
【杀不死的倒计时】一个简单易用的倒计时View,常用于快速创建点击获取验证码按钮,支持各种自定义样式。(特点:重新进入当前页面或重启程序倒计时不会重置,仍将继续执行,且退出程序后的时间也会被自动计算在内)

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to ZXCountDownView

CountdownTimer-TeLeTiPs
The very first powerful Telegram bot to countdown to your important events in any group chat. Live countdown timer (days : hours : minutes : seconds)
Stars: ✭ 122 (+117.86%)
Mutual labels:  countdown, countdown-timer
vue-flip-down
vue 翻页倒计时组件 妙啊
Stars: ✭ 90 (+60.71%)
Mutual labels:  countdown, countdown-timer
CountdownView
Simple countdown view with custom animations
Stars: ✭ 70 (+25%)
Mutual labels:  countdown, countdown-timer
react-timer-wrapper
Composable React Timer component that passes status props to children, in addition to some basic callbacks. Can be used at a countdown timer ⏲ or as stopwatch ⏱ to track time while active.
Stars: ✭ 14 (-75%)
Mutual labels:  countdown, countdown-timer
yii2-time-down-counter
Widget for yii2, to start count down timer with a lot of options, This widget build dependence of timeDownCounter JS library
Stars: ✭ 15 (-73.21%)
Mutual labels:  countdown, countdown-timer
howlonguntilprayuthleaves.com
นับเวลาถอยหลังถึงวันที่พลเอกประยุทธ์ จันทร์โอชา หมดวาระการเป็นนายกรัฐมนตรี
Stars: ✭ 29 (-48.21%)
Mutual labels:  countdown, countdown-timer
CountDownTimerSwift
This is a simple and beautiful countdown timer project done using swift
Stars: ✭ 18 (-67.86%)
Mutual labels:  countdown-timer
alfred-timer-workflow
Alfred workflow to start a timer, which blinks when the time is up.
Stars: ✭ 39 (-30.36%)
Mutual labels:  countdown
countdown
jQuery CountDown Clock - Simple countdown plugin for product special offers
Stars: ✭ 33 (-41.07%)
Mutual labels:  countdown
countdown-vuejs
A Countdown Timer component for Vue.js
Stars: ✭ 58 (+3.57%)
Mutual labels:  countdown-timer
Glaedr
An extensive, modular functional scoreboard library for the Bukkit/Spigot API.
Stars: ✭ 23 (-58.93%)
Mutual labels:  countdown
angular2-simple-countdown
a simple countdown angular2 directive with multiple language
Stars: ✭ 26 (-53.57%)
Mutual labels:  countdown
tiktok
🕑 A countdown chrome extension for tasks/events/whatever.
Stars: ✭ 22 (-60.71%)
Mutual labels:  countdown
timeleft
⏳ Don't waste your time or time will waste you! ☠️ One tends to consume time on low-return stuff, superficial entertainment. 📺 Things they don't actually want to do. One should make the most of his time. ⏱ Get busy living.
Stars: ✭ 18 (-67.86%)
Mutual labels:  countdown
nypsi
the best discord bot
Stars: ✭ 41 (-26.79%)
Mutual labels:  countdown
moveit
Move.it is a project that combines the pomodoro (🍅 ) technique with some challenges (⚔️ ) for the well-being (🥰 ) of those who spend many hours (⏳ ) using the computer 🖥
Stars: ✭ 12 (-78.57%)
Mutual labels:  countdown
react-component-countdown-timer
This is a simple count down timer react component.
Stars: ✭ 18 (-67.86%)
Mutual labels:  countdown
osx-statusbar-countdown
⏳📅 A utility to count down to a date from your macOS menubar, written in Swift
Stars: ✭ 40 (-28.57%)
Mutual labels:  countdown
CountdownTimer
Countdown timer app built in Jetpack Compose
Stars: ✭ 38 (-32.14%)
Mutual labels:  countdown-timer
Web-Time-Tracker
Plugin named Timetracker is a time counter that works in both increase and decrease directions.
Stars: ✭ 21 (-62.5%)
Mutual labels:  countdown

ZXCountDownView

License MIT  CocoaPods  CocoaPods  Support 

安装

通过CocoaPods安装

pod 'ZXCountDownView'

手动导入

  • 将ZXCountDownView拖入项目中。

导入头文件

#import "ZXCountDownView.h"

效果图

Image text


Demo

ZXCountDownLabel

  • 在控制器的viewDidLoad方法中设置一个倒计时Label,重启App后仍然保持倒计时进度:
//第一个参数40即为倒计时时间为40秒,第二个参数mark用于标记区分当前倒计时任务和其他倒计时任务,确保与其他任务不重名即可,block第一个参数即为剩余秒数,block返回值即为显示在Label上的文字。(此处实现了一个倒计时40秒,且显示”还剩40、39、38...秒哦“的Label)
[self.scheduleStoreLabel setCountDown:40 mark:@"ScheduleStoreLabel" resTextFormat:^NSString *(long remainSec) {
    if(remainSec > 30){
        weakSelf.scheduleStoreLabel.backgroundColor = [UIColor orangeColor];
    }else{
        weakSelf.scheduleStoreLabel.backgroundColor = [UIColor redColor];
    }
    //显示剩余几分几秒
    NSString *timeformatStr = [NSDate getDateStrWithSec:remainSec dateFormat:@"mm分ss秒"];
    return timeformatStr;
}];
  • 开始倒计时
[self.scheduleStoreLabel startCountDown];

ZXCountDownBtn

  • 与ZXCountDownLabel类似

ZXAutoCountDownBtn

  • 在控制器的viewDidLoad方法中设置一个点击获取验证码的Button,且点击后自动开启倒计时,重启App后仍然保持倒计时进度:
//此处实现了一个倒计时20秒,且显示“还剩20、19、18...秒后重试”的Btn,且退出重新进入当前控制器或重启App不受影响。
[self.getCheckCodeBtn enableAutoCountDown:20 mark:@"GetCheckCodeBtn" resTextFormat:^NSString *(long remainSec) {
    return [NSString stringWithFormat:@"%ld秒后重发",remainSec];
}];
#pragma mark 点击了获取验证码按钮
- (IBAction)getCheckCodeAction:(id)sender {
    //判断如果手机号码不合法,可不触发倒计时
    if(0){
        self.getCheckCodeBtn.start = NO;
        return;
    }
    //如果需要过2秒再执行倒计时
    if(0){
        self.getCheckCodeBtn.terminateCountDown = YES;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.getCheckCodeBtn startCountDown];
            NSLog(@"执行获取验证码操作!!");
        });
        return;
    }
    NSLog(@"执行获取验证码操作!!");
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //判断如果验证码请求失败,可重置倒计时按钮
        if(0){
            [self.getCheckCodeBtn resume];
        }
        
    });
}

ZXCountDownCore

  • 您也可以不依赖UI控件,直接开启一个倒计时任务
ZXCountDownCore *countDownCore = [[ZXCountDownCore alloc]init];
[countDownCore setCountDown:10 mark:@"testCountDown" resBlock:^(long remainSec) {
    //每秒执行一次
    NSLog(@"remainSec--%ld",remainSec);
}];
//开始倒计时
[countDownCore startCountDown];
  • 【注意:】countDownCore对象必须使用强指针引用,否则会立即被销毁,导致倒计时无效

Other

  • 启用或禁用自动存储倒计时进度:
//disableScheduleStore 是否不存储倒计时进度,默认为NO,即默认存储倒计时进度,若存储倒计时进度,则重启App或重新进入当前控制器,倒计时将无缝继续执行
view.disableScheduleStore = YES;
view.disableScheduleStore = NO;
  • 通用倒计时控制:
//开始倒计时
[view startCountDown];
///暂停倒计时
[view pauseCountDown];
//重新开始倒计时
[view reStartCountDown];
//结束倒计时
[view stopCountDown];
///关闭倒计时
[view invalidateTimer];
  • 禁止倒计时停止时恢复到最初的状态(文字、文字颜色、文字背景色),默认为否,若为否,则remainSec == 0时设置的状态将无效
view.disableResumeWhenEnd = YES;
  • 获取当前倒计时view的状态
ZXCountViewStatus countViewStatus = view.countViewStatus;
//countViewStatus有以下枚举:
//ZXCountViewStatusEnded = 0x00,    // 倒计时View倒计时未开始或已结束
//ZXCountViewStatusPaused = 0x01,    // 倒计时View已暂停
//ZXCountViewStatusRunning = 0x02,    // 倒计时View正在倒计时

注意

  • 若需要实现多个不同的倒计时view共用进度,例如登录获取验证码按钮,注册获取验证码按钮,找回密码获取验证码按钮,只需设置相同mark即可。
  • ZXCountDownView中倒计时结束默认会将UI控件设置回最初的状态,例如刚开始倒计时按钮文字为“点击获取验证码”,倒计时结束您需要设置为“重新获取”,则您需要设置btn.disableResumeWhenEnd = YES,禁止自动将空间设置回最初的状态,并且在resTextFormat中判断remainSec == 0时将按钮设置为“重新获取”即可。
  • 若倒计时view执行了暂停操作且倒计时view自动储存进度开启,则重新初始化倒计时view时,它将仍然处于暂停状态。
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].