• 倒计时,


    - (void)timerFireMethod:(NSTimer *)timer

    {

        NSDate* now = [NSDate date];

        NSCalendar *cal = [NSCalendar currentCalendar];

        

        unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |NSSecondCalendarUnit;

        NSDateComponents *dd = [cal components:unitFlags fromDate:now];

        int y = [dd year];

        int m = [dd month];

        int d = [dd day];

        NSCalendar *calendar = [NSCalendar currentCalendar];

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

        [components setYear:y];

        [components setMonth:m];

        [components setDay:d];

        [components setHour:18];

        [components setMinute:30];

        [components setSecond:0];

        NSDate *fireDate = [calendar dateFromComponents:components];//标时间

        NSDateComponents *dComponent = [calendar components:unitFlags fromDate:now toDate:fireDate options:0];//计算时间差

    //    self.hourminutesecondLabel

        

        NSMutableAttributedString *mutiStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%d:%d:%d",[dComponent hour],[dComponent minute],[dComponent second]]];

        NSString *secondLen = [NSString stringWithFormat:@"%d",[dComponent second]];

        [self.hourminutesecondLabel setText:mutiStr afterInheritingLabelAttributesAndConfiguringWithBlock:

         

         ^NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {

             

             [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)RGBCOLOR(6, 193, 174) range:NSMakeRange(0, 3)];

             [mutableAttributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue" size:39.0] range:NSMakeRange(mutiStr.length - secondLen.length, secondLen.length)];

     

             return mutableAttributedString;//需要有返回值的,

             

         }];

        if ([dComponent second] < 0) {

            self.hourminutesecondLabel.text = @"下班啦";

        }

       

     

    }

  • 相关阅读:
    python虚拟环境--virtualenv
    求导法则和高阶导数
    restful规范
    python协程--yield和yield from
    打印质数
    更改docker的存储位置
    同台ECS安装多个mysql
    jenkins + gitlab + harbor + k8s 部署项目
    jenkins 配置maven
    gitlab + jenkins 持续集成
  • 原文地址:https://www.cnblogs.com/guligei/p/3941716.html
Copyright © 2020-2023  润新知