zoukankan      html  css  js  c++  java
  • 倒计时demo

    #import <UIKit/UIKit.h>

    @interface ViewController : UIViewController

    @property (strong,nonatomic) UILabel *titleLable;

    @property (strong,nonatomic) UILabel *showTimeLable;

    @property (strong,nonatomic) UIView *bottomView;

    @property (strong,nonatomic) NSString *setTime;

    @property (strong,nonatomic) NSArray *timeArr;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(88, 40, 200, 140)];

        self.titleLable.backgroundColor = [UIColor clearColor];

        self.titleLable.numberOfLines = 0;

        self.titleLable.textColor = [UIColor purpleColor];

        self.titleLable.textAlignment = NSTextAlignmentCenter;

        self.titleLable.font = [UIFont systemFontOfSize:30];

        [self.view addSubview:self.titleLable];

        

        self.showTimeLable = [[UILabel alloc] initWithFrame:CGRectMake(88, 190, 200, 200)];

        self.showTimeLable.backgroundColor = [UIColor grayColor];

        self.showTimeLable.textAlignment = NSTextAlignmentCenter;

        self.showTimeLable.font = [UIFont systemFontOfSize:30];

        self.showTimeLable.numberOfLines = 0;

        self.showTimeLable.textColor = [UIColor yellowColor];

        self.showTimeLable.layer.cornerRadius = self.showTimeLable.frame.size.width / 2;

        self.showTimeLable.clipsToBounds = YES;

        [self.view addSubview:self.showTimeLable];

        self.setTime = @"2016-6-1";

        self.timeArr = [self.setTime componentsSeparatedByString:@"-"];

        [self refreshTime];

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

        

        

        

        

    }

    -(void)refreshTime

    {

        NSCalendar *laterCalender = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

        NSDateComponents *latercomponents = [[NSDateComponents alloc] init];

        latercomponents.year = [self.timeArr[0] integerValue];

        latercomponents.month = [self.timeArr[1] integerValue];

        latercomponents.day = [self.timeArr [2] integerValue];

        NSDate *laterDate = [laterCalender dateFromComponents:latercomponents];

        NSDateComponents *betweenDate = [laterCalender components:NSCalendarUnitSecond fromDate:[NSDate date] toDate:laterDate options:0];

        

        

        if (betweenDate.second < 0) {

            self.showTimeLable.text = [self DayHourMunintSecond:-betweenDate.second];

            

            self.titleLable.text = [NSString stringWithFormat:@"距离 %@ 已经过时",self.setTime];

        }

        

        else{

            self.showTimeLable.text = [self DayHourMunintSecond:betweenDate.second];

            self.titleLable.text = [NSString stringWithFormat:@"距离 %@ 结课还有",self.setTime];

            

        }

        

        

    }

    -(NSString *)DayHourMunintSecond:(NSInteger)time

    {

        NSString *timeString;

        timeString = [NSString stringWithFormat:@"%ld秒",time % 60];

        

        time /= 60;

        if (time > 0) {

            timeString = [NSString stringWithFormat:@"%ld分 %@",time % 60,timeString];

        }

        

        time /= 60;

        if (time > 0) {

            timeString = [NSString stringWithFormat:@"%ld时 %@",time % 24,timeString];

        }

        

        time /= 24;

        if (time > 0) {

            timeString = [NSString  stringWithFormat:@"%ld天 %@",time,timeString];

        }

        

        return timeString;

    }

  • 相关阅读:
    Surface RT2装Win10出现 "INF不包含数字签名信息"【已解决】
    树上倍增LCA模版
    sql注入
    python 调用 telnet
    ss
    【总结氵】2021.02.27 省选模拟
    2021.03.13省选模拟 抽卡(card)
    树链剖分之重链剖分 模板
    多项式求逆 模板
    NTT快速数论变换 模板
  • 原文地址:https://www.cnblogs.com/wujie123/p/5361023.html
Copyright © 2011-2022 走看看