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

    - (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 = @"下班啦";

        }

       

     

    }

  • 相关阅读:
    .Net 开源项目资源大全
    无法向会话状态服务器发出会话状态请求
    网站限制不能点击右键
    ashx页面中context.Session["xxx"]获取不到值的解决办法
    SQL Server 2008 错误 233 的解决办法
    Best MVC Practices 最佳的MVC实践
    char* 转换成 CString
    MFC圆角背景移动边角底色毛刺解决方案
    CString转换为const char*
    分享一份安卓开发包,集成开发环境
  • 原文地址:https://www.cnblogs.com/guligei/p/3941716.html
Copyright © 2011-2022 走看看