IOS关键代码:
- (void)viewDidLoad {
[super viewDidLoad];
[self updateTime];
[NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
}
-(void)updateTime
{
NSString *time = [self getCurrentTime];
timeLabel.text = time;
[timeLabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:25.0]];
[timeLabel setTextAlignment:UITextAlignmentCenter];
[timeLabel setTextColor:[UIColor redColor]];
[self.view setBackgroundColor:[UIColor blackColor]];
}
- (NSString *) getCurrentTime{
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSString *currentTime = [dateFormatter stringFromDate:today];
[dateFormatter release];
return currentTime;
}
本文介绍了一个简单的iOS应用案例,该应用使用Objective-C编程语言实现在屏幕上定时更新并显示当前时间的功能。通过NSTimer调度器每秒调用一次updateTime方法来更新UILabel上的时间显示。
420

被折叠的 条评论
为什么被折叠?



