在特定时间后更改 UILabel [英] Changing a UILabel after a specific time

查看:26
本文介绍了在特定时间后更改 UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点卡住了,需要一些想法.

Im a bit stuck and need some ideas.

我想制作一个应用,它从 0-12 开始计数,然后另一个 UILabel 变为 1.第一个标签再次从 0-12 开始,然后标签变为 2.依此类推...

I want to make an app where it counts up from 0-12 then another UILabel changes to 1. The first label starts again from 0-12 then the label changes to 2. So on...

我尝试了几种方法来添加 NSTimer 调度定时器并制作一些选择器,它在一定程度上起作用,但不是我喜欢的.

I have tried a few ways adding in a NSTimer scheduledTimer and making a few selectors it worked to a certain extent but not to my liking.

我不需要任何代码示例(虽然会很好)但只有一些想法会很好谢谢.:)

I don't need any code examples (although would be nice) but just some ideas would be nice thanks. :)

推荐答案

您想根据时间更改标签还是按按钮?

do you want to change label according to time or by press button?

所以你想通过计时器更改标签,所以在这里.

So you want to change label by timer so here it is.

拳头

#define TimeIntervelInSec 1.0
#define countMaxLimitForLower 12

在 .h 文件中生成 2 个 int

Make 2 int in your .h file

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];

}

这篇关于在特定时间后更改 UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆