随着时间的推移改变 UILabel ?

发布于 2024-09-01 08:02:09 字数 62 浏览 6 评论 0原文

我有一个简单的 UILabel,我想每 10 秒更改一次文本。最好的方法是什么,让界面的其余部分保持活动状态?

I have a simple UILabel on that I want to change the text of every 10 seconds. What is the best way of doing this, which let's the rest of the interface remain active?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放我走吧 2024-09-08 08:02:09
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(updateLabel:) userInfo:nil repeats:YES];
self.repeatingTimer = timer;
...

- (void) updateLabel:(id)sender {
    myLabel.text = newStringValue;
}

...
[repeatingTimer invalidate];
self.repeatingTimer = nil; // stops timer
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(updateLabel:) userInfo:nil repeats:YES];
self.repeatingTimer = timer;
...

- (void) updateLabel:(id)sender {
    myLabel.text = newStringValue;
}

...
[repeatingTimer invalidate];
self.repeatingTimer = nil; // stops timer
夏尔 2024-09-08 08:02:09

您所需要的只是启动一个 NSTimer 并每次更新 label.text 。

All you need is to start an NSTimer and update the label.text each time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文