我有点卡住了,需要一些想法。
我想制作一个应用程序,它从 0-12 开始计数,然后另一个 UILabel 变为 1。第一个标签再次从 0-12 开始,然后标签变为 2。依此类推...
我已经尝试了几种方法来添加 NSTimer scheduledTimer 并制作一些选择器,它在一定程度上起作用但不是我喜欢的。
我不需要任何代码示例(虽然会很好)但只要一些想法就很好,谢谢。 :)
最佳答案
你是想按时间换标签还是按按钮换标签?
所以你想通过计时器更改标签,所以在这里。
拳头
#define TimeIntervelInSec 1.0
#define countMaxLimitForLower 12
在你的 .h 文件中创建 2 int
int countLower;
int countHigher;
IBOutlet UILabel *lblLowerCount;
IBOutlet UILabel *lblHigherCount;
并且放在 .m 中
- (void)viewDidLoad
{
[super viewDidLoad];
countLower = 0;
countHigher = 0;
[NSTimer scheduledTimerWithTimeInterval:TimeIntervelInSec
target:self
selector:@selector(timerChanged)
userInfo:nil
repeats:YES ];
}
-(void)timerChanged
{
if (countLower >= countMaxLimitForLower)
{
countHigher++;
countLower = 0;
}
else
{
countLower ++;
}
lblLowerCount.text = [NSString stringWithFormat:@"%d",countLower];
lblHigherCount.text = [NSString stringWithFormat:@"%d",countHigher];
}
关于ios - 在特定时间后更改 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22281691/