zoukankan      html  css  js  c++  java
  • 短信验证倒计时按钮

    #import <UIKit/UIKit.h>


    @interface SecondsButton : UIButton


    - (void)startCountdown;

    //- (void)pauseCountdown;

    //- (void)resumeCountdown;


    @end

     --------------------------

    #import "SecondsButton.h"


    #define SECOND 60


    @interface SecondsButton ()

    {

        NSTimer *_timer;

        NSInteger _seconds;

    }

    @end


    @implementation SecondsButton


    - (id)initWithFrame:(CGRect)frame

    {

        self = [super initWithFrame:frame];

        if (self) {

            // Initialization code

            self.opaque = YES;

            

            self.titleLabel.font = [UIFont systemFontOfSize:12.0f];

        

    //        [self setBackgroundImage:[zhuiUtils imageWithColor:[UIColor colorWithHexString:@"a7a9ab"] andSize:CGSizeMake(frame.size.width, frame.size.height)] forState:UIControlStateDisabled];

    //        [self setBackgroundImage:[zhuiUtils imageWithColor:[UIColor colorWithHexString:@"5aa4d1"] andSize:CGSizeMake(frame.size.width, frame.size.height)] forState:UIControlStateNormal];

    //        

    //        [self setBackgroundImage:[zhuiUtils imageWithColor:[UIColor colorWithHexString:@"3781ae"] andSize:CGSizeMake(frame.size.width, frame.size.height)] forState:UIControlStateHighlighted];

            

            _seconds = SECOND;

            

            NSString *title = lnreget(_seconds);

            

            [self setTitle:title forState:UIControlStateDisabled];

            [self setTitle:lngetcheckcode forState:UIControlStateNormal];


        }

        return self;

    }


    #pragma mark - public methods

    - (void)startCountdown

    {

        _timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:YES];

        

        self.enabled = NO;

    }

    //- (void)pauseCountdown

    //{

    //    if (![_timer isValid]) {

    //        return ;

    //    }

    //    

    //    //[self setFireDate:[NSDate dateWithTimeIntervalSinceNow:0]];

    //    [_timer setFireDate:[NSDate distantFuture]]; //如果给我一个期限,我希望是4001-01-01 00:00:00 +0000

    //}

    //

    //- (void)resumeCountdown

    //{

    //    if (![_timer isValid]) {

    //        return ;

    //    }

    //    

    //    //[self setFireDate:[NSDate dateWithTimeIntervalSinceNow:0]];

    //    [_timer setFireDate:[NSDate date]];

    //

    //}


    //-(void)release

    //{

    //    if (timer) {

    //        if ([timer respondsToSelector:@selector(isValid)]) {

    //            if ([timer isValid]) {

    //                [timer invalidate];

    //                seconds = 60;

    //            }

    //        }

    //    }

    //}


    #pragma mark - NSTimer private methods

    - (void)timerFireMethod:(NSTimer*)theTimer

    {

        if (_seconds == 0) {

            if ([_timer respondsToSelector:@selector(isValid)]) {

                if ([_timer isValid]) {

                    [_timer invalidate];

                    _timer = nil;

                }

            }

            _seconds = SECOND;

            [self setTitle:lngetcheckcode forState:UIControlStateNormal];

            self.enabled = YES;

        }else{

            _seconds--;

            NSString *title = lnreget(_seconds);

            

            [self setTitle:title forState:UIControlStateDisabled];

            

        }

    }


    #pragma mark - Memory methods

    -(void)dealloc

    {

        if (_timer) {

            if ([_timer respondsToSelector:@selector(isValid)]) {

                if ([_timer isValid]) {

                    [_timer invalidate];

                    

                }

            }

        }

    //    [super dealloc];

    }


    @end

  • 相关阅读:
    使用pycharm开发代码上传到GitLab和GitHub
    私有仓库GitLab快速入门篇
    修改Linux Operating System的时间与时区
    版本控制工具Git工具快速入门-Linux篇
    Hadoop生态圈-Oozie实战之调度shell脚本
    Hadoop生态圈-Oozie实战之逻辑调度执行多个Job
    JavaScript基础知识-相等运算符
    Hadoop生态圈-Oozie部署实战
    Tomcat定义虚拟主机案例
    Tomcat的配置文件详解
  • 原文地址:https://www.cnblogs.com/modaoyicheng/p/4828120.html
Copyright © 2011-2022 走看看