In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces iOS how to achieve flash sale activity countdown, the article is very detailed, has a certain reference value, interested friends must read it!
IOS about large-scale website rush to buy, from the end of the event, the remaining time countdown implementation code, the code is relatively simple, we according to the needs of the appropriate addition, modification and deletion of the code
1. Define 4 Label to receive the countdown:
@ property (weak, nonatomic) IBOutlet UILabel * dayLabel;@property (weak, nonatomic) IBOutlet UILabel * hourLabel;@property (weak, nonatomic) IBOutlet UILabel * minuteLabel;@property (weak, nonatomic) IBOutlet UILabel * secondLabel
two。 Implement the method in the implementation file:
/ / time stamp is converted to date format (time stamp in milliseconds)-(NSString *) timeWithTimeIntervalString: (NSString *) timeString {/ / format time NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; formatter.timeZone = [NSTimeZone timeZoneWithName:@ "shanghai"]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@ "yyyy-MM-dd HH:mm:ss"] / / the millisecond value is converted to NSDate* date = [NSDate dateWithTimeIntervalSince1970: [timeString doubleValue] / 1000.0]; NSString* dateString = [formatter stringFromDate:date]; NSLog (@ "time = =% @", dateString); return dateString;}-(void) downSecondHandle: (NSString*) aTimeString {NSDateFormatter * dateFormatter= [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@ "yyyy-MM-dd HH:mm:ss"]; NSDate* endDate = [dateFormatter dateFromString: [self timeWithTimeIntervalString:aTimeString]] / / end time NSDate * endDate_tomorrow = [[NSDate alloc] initWithTimeIntervalSinceReferenceDate: ([endDate timeIntervalSinceReferenceDate])]; NSDate * startDate = [NSDate date]; NSString* dateString = [dateFormatter stringFromDate:startDate]; NSLog (@ "time now =% @", dateString); NSTimeInterval timeInterval = [endDate_tomorrow timeIntervalSinceDate:startDate]; if (_ timer==nil) {_ _ block int timeout = timeInterval / / countdown time if (timeouttiming queue 0) {dispatch_queue_t queue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); _ timer = dispatch_source_create (DISPATCH_SOURCE_TYPE_TIMER, 0,0Powerqueue); dispatch_source_set_timer (_ timer,dispatch_walltime (NULL, 0), 1.0*NSEC_PER_SEC, 0); / / execute dispatch_source_set_event_handler (_ timer, ^ {if (timeout) per second
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.