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

  • 相关阅读:
    JavaScript数组操作
    cxf-rs 和 swagger 的点
    cxf-rs 、spring 和 swagger 环境配置切换【github 有项目】
    (二)swagger-springmvc
    (二)spring-mvc-showcase 和 swagger-springmvc 的恩恩怨怨
    svn 创建tag
    swagger 入门
    jax-rs
    swagger core 和 swagger ui 如何关联【窥探】
    配置 struts2 时掉进 web.xml 的坑
  • 原文地址:https://www.cnblogs.com/modaoyicheng/p/4828120.html
Copyright © 2011-2022 走看看