iPhone数字时钟 [英] iPhone Digital Clock

查看:267
本文介绍了iPhone数字时钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很长时间让模拟时钟工作之后,我试图制作一个数字时钟(叹气).我正在尝试使用10个PNG(数字0-9)来做到这一点.时钟的每个数字都将是一幅图像.唯一的问题是从当前时间检索某个数字.我尝试将时间转换为字符串并使用characterAtIndex,但这似乎不起作用.解决这个问题的最佳方法是什么?

After the long time I spent getting an analog clock to work, I am trying to make a digital one (sigh). I am trying to do this with 10 PNGs with the numbers 0 - 9. Each digit of the clock would be an image. The only problem with this is retrieving the certain digit from the current time. I've tried converting the time to a string and using the characterAtIndex, but that doesn't seem to work. What would be the best way to get around this?

推荐答案

您可以使用NSDateComponentsNSCalendar:

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;

这篇关于iPhone数字时钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆