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

  • 相关阅读:
    三、python函数基础
    二、python算法逻辑基础
    RE正则表达式-语法
    read方法读取ini文件报错'gbk' codec can't decode
    git bash常用命令
    xlrd、xlwt、xlutils模块操作excel文件
    Git命令行克隆项目
    浏览器console,web自动化常用的几种定位调试使用方法总结
    css定位正则匹配和模糊匹配
    罗马数字转整数
  • 原文地址:https://www.cnblogs.com/modaoyicheng/p/4828120.html
Copyright © 2011-2022 走看看