您的位置:首页 > 移动开发 > IOS开发

iOS系统通知,与自定义显示时间

2016-04-18 00:00 489 查看
摘要: 最近的项目需求有一个:隐藏系统时间,自定一个时间显示

链接为上一个作者,感谢最源头的兄弟的总结,也感谢转载它的兄弟,让我可以看得到,并且我也转载一下,让更多人看到。

http://www.jianshu.com/p/5bae90250980,源作者好像是github上面总结的。

更新:后来采用NSTimer 的方式代码如下:(但是上面的链接里面有很多系统通知,以后可能会用到,保留一下)

[code=plain]_timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timeChange:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop]addTimer:_timer forMode:NSDefaultRunLoopMode];
[_timer fire];

- (void)timeChange:(id )sender{

NSDate *currentDate = [NSDate date];//获取当前时间,日期
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:currentDate];
if ([dateString hasPrefix:@"0"]) {
dateString = [dateString substringFromIndex:1];
}

_timeLabel.text = dateString;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息