IOS Countdown Nstimer

Source: Internet
Author: User

Where there may be some countdown in the project

For example, when the mobile phone verification, the verification code will generally have a time limit, at this point in the code to enter the place you need to show a countdown


The detailed implementation is the use of iOS comes with the Nstimer


On the Code

First new


    int Secondscountdown; Countdown Total time length    nstimer *countdowntimer;    UILabel *labeltext;


And then implement it in detail


    Create UILabel Add to Current View    Labeltext=[[uilabel Alloc]initwithframe:cgrectmake (ten, +, +)];    [Self.view Addsubview:labeltext];        Set Countdown total duration    Secondscountdown = 60;//60 seconds Countdown    //Start countdown    Countdowntimer = [Nstimer Scheduledtimerwithtimeinterval:1 target:self selector: @selector (Timefiremethod) Userinfo:nil Repeats:yes]; A method is called every second after the countdown is started Timefiremethod        //Set the countdown display time    labeltext.text=[nsstring stringwithformat:@ "%d", Secondscountdown];

Implementing a method that runs every second

-(void) timefiremethod{    //Countdown-1    secondscountdown--;    Change the countdown tag reality content    labeltext.text=[nsstring stringwithformat:@ "%d", Secondscountdown];    When the countdown to 0 o'clock. Do the required operation, for example, the verification code expires cannot submit    if (secondscountdown==0) {        [countdowntimer invalidate];        [LabelText Removefromsuperview];}    }


Have been broadly implemented, there are problems to continue to communicate


Apple Development Group: 414319235 Welcome to add welcome discussion questions






IOS Countdown Nstimer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.