首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iPhone数字时钟

iPhone数字时钟
EN

Stack Overflow用户
提问于 2011-02-03 02:00:25
回答 1查看 1.1K关注 0票数 0

在我花了很长时间准备一个模拟时钟工作后,我正试图制作一个数字时钟(叹息)。我试着用数字0- 9的10个PNG来做这件事。时钟的每一个数字都是一幅图像。唯一的问题是从当前时间中检索特定的数字。我尝试过将时间转换为字符串并使用characterAtIndex,但这似乎行不通。什么是最好的方法来绕过这件事?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-03 02:06:50

你可以用NSDateComponentsNSCalendar

代码语言:javascript
复制
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;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4881992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档