一个 UILabel
子类,用于显示倒计时
JBCountdownLabel
是一个 UILabel
子类,可以显示一个定义了秒数的倒计时。因此,您可以像使用原生的 UILabel
一样自定义标签,并添加一些酷炫的操作。
我建议使用 CocoaPods 来安装 JBCountdownLabel。只需将以下行添加到您的 Podfile
中。
pod 'JBCountdownLabel'
但您也可以直接将 JBCountdownLabel.m
和 JBCountdownLabel.h
拖到您的项目中。
将标签添加到您的视图中
self.countdownLabel = [[JBCountdownLabel alloc] initWithFrame:CGRectMake(0, 50, 320, 46) format:@"Initiating ignition in %@" time:300 delegate:self];
self.countdownLabel.textColor = [UIColor colorWithRed:0.48 green:0.63 blue:0.07 alpha:1];
[self.view addSubview:self.countdownLabel];
您可以更改倒计时的行为
- (void)restartCountdown;
- (void)cancelCountdown;
- (void)setTime:(int)seconds;
有一个可选的 delegate
回调,以便在倒计时结束时通知您
- (void)countdownFinnishInCountdown:(JBCountdownLabel *)countdown;
在 Xcode 中构建并运行 JBCountdownLabelSampleProject
项目,以查看 JBCountdownLabel
的实际效果。
此代码最初是为了在 meets 下载应用并进行免费测试而创建的!欢迎提供反馈!
Javier Berlana
JBCountdownLabel 可在 MIT 许可证下使用。有关更多信息,请参阅 LICENSE 文件。