• 倒计时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;

    }

  • 相关阅读:
    android11——Material Design
    android10——Internet
    Andrid09——Service
    Android08——MultiMedia
    Android07——ContentProvider
    Android06——Persistence
    <转>汇编源码调试
    编程中我犯过的错误一
    中国社会9大阶层划分,看看你在哪一层?
    汇编中如果汇编和调用API混合用的话要注意Pushad popad
  • 原文地址:https://www.cnblogs.com/wujie123/p/5361023.html
Copyright © 2020-2023  润新知