Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the countdown to flash sale activity by iOS

2025-03-10 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report