在我花了很长时间准备一个模拟时钟工作后,我正试图制作一个数字时钟(叹息)。我试着用数字0- 9的10个PNG来做这件事。时钟的每一个数字都是一幅图像。唯一的问题是从当前时间中检索特定的数字。我尝试过将时间转换为字符串并使用characterAtIndex,但这似乎行不通。什么是最好的方法来绕过这件事?
发布于 2011-02-03 02:06:50
你可以用NSDateComponents和NSCalendar
NSDate * date = [NSDate date];
NSCalendar * calendar = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents * components =
[calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:date];
NSInteger hour = [weekdayComponents hour];
NSInteger minute = [weekdayComponents minute];
NSInteger firstHourDigit = hour/10;
NSInteger secondHourDigit = hour%10;
NSInteger firstMinuteDigit = minute/10;
NSInteger secondMinuteDigit = minute%10;https://stackoverflow.com/questions/4881992
复制相似问题