Git Product home page Git Product logo

countdownbutton's Introduction

countDownButton

countDownButton,子类化UIButton实现iOS倒计时按钮,常常用于注册等发送验证码的时候进行倒计时操作

countDownButton, subclassing UIButton implementation iOS countdown button, register with sending the verification code and countdown

Demo

Demo

Installation

Installation with CocoaPods

platform:ios,'7.0'
target 'YourProjectName' do
pod 'countDownButton'
end

Manually

Copy countDownButton.h countDownButton.m in LFCountDownButton/ to your project.

Usage

Code

@property(nonatomic,strong) LFCountDownButton *countDownButton;


//创建倒计时按钮
 self.countDownButton = [[LFCountDownButton alloc]init];
 self.countDownButton.frame = CGRectMake(10, 130, 150, 40);
[self.countDownButton.titleLabel setFont:[UIFont systemFontOfSize:14.0f]];
[self.countDownButton setTitle:@"Start CountDown" forState:UIControlStateNormal];
[self.countDownButton setBackgroundColor:[UIColor redColor]];
[self.view addSubview:self.countDownButton];

// 1. 倒计时按钮点击
[self.countDownButton touchCountDownButtonHandler:^(LFCountDownButton *countDownButton, NSInteger tag) {
    
    countDownButton.enabled = NO;
    
    //1.1开始倒计时
    [countDownButton startCountDownWithSecond:10];
    
    //do something...
    
    //1.2 倒计时进行中
    [countDownButton countDownButtonChanging:^NSString *(LFCountDownButton *countDownButton, NSUInteger second) {
     
        NSString *title = [NSString stringWithFormat:@"%zd left",second];
        return title;
        
    }];
    
    //1.3 倒计时结束
    [countDownButton countDownButtonFinished:^NSString *(LFCountDownButton *countDownButton, NSUInteger second) {
     
        countDownButton.enabled = YES;
        return @"Obtain again";
        
    }];

}];

###xib @property (weak, nonatomic) IBOutlet LFCountDownButton *countDownButtonXib;

1.拖拽button控件到xib 2.修改button控件的的类,button type要设置成custom 否则会闪动 3.设置IBAction方法

- (IBAction)countDownButtonClickForXib:(id)sender {

 //要么拖拽方法的时候改变type(id改为LFCountDownButton类型),要么自己转下
 self.countDownButtonXib = (LFCountDownButton*)sender;
 self.countDownButtonXib.enabled = NO;

//1.1开始倒计时
[ self.countDownButtonXib startCountDownWithSecond:15];

//do something...

//1.2 倒计时进行中
[ self.countDownButtonXib countDownButtonChanging:^NSString *(LFCountDownButton *countDownButton, NSUInteger second) {
    
    NSString *title = [NSString stringWithFormat:@"%zd left",second];
    return title;
    
}];

//1.3 倒计时结束
[ self.countDownButtonXib countDownButtonFinished:^NSString *(LFCountDownButton *countDownButton, NSUInteger second) {
    
    countDownButton.enabled = YES;
    return @"Obtain again";
}];
}

License

This code is distributed under the terms and conditions of the MIT license.

countdownbutton's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

carabina

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.