更新时间标签的简单组件。
每当指定的日历单元发生变化时通知您。所有操作均通过使用 Foundation 框架完成。没有魔法 stuff :)
假设您想显示一个时间标签,该标签将显示小时和分钟。但为了保持分钟同步,您必须设置一个定时器,该定时器每秒触发一次。
但是,使用这个库只需每分钟触发一次。它也很容易使用。
// self.timeLabel is instance of UILabel
// self.dateFormatter is instance of NSDateFormatter
__weak __typeof(self) w_self = self;
self.calendarLink = [[RKCalendarLink alloc] initWithCalendarUnit:NSCalendarUnitMinute updateBlock:^{
w_self.timeLabel.text = [w_self.dateFormatter stringFromDate:[NSDate date]];
}];
要查看它的工作状态,请下载此仓库并运行示例项目。
注意:Mac 未经过测试,但它应该工作。
RKCalendarLink 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'RKCalendarLink', '~> 0.1'
Roman Kříž,[email protected]
RKCalendarLink 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。