如何拥有动态(自动)更新滑块值的标签?

发布于 2024-12-03 06:42:40 字数 239 浏览 0 评论 0原文

我的 iOS 应用程序中有一个标签和滑块,并且遇到了这个问题。

我想让标签读取滑块的值,我已经通过使用带有按钮的 IBAction 来做到这一点,这样每当按下按钮时,标签就会更新滑块的值。代码是这样的:

label.text = [NSString stringWithFormat:@"%f", slider.value]; 

它可以工作,那么现在如何使标签在拖动滑块时更新值?

I have a label and slider in my iOS application and I have run into this problem.

I want to have the label read the value of the slider, and I have done that by using an IBAction with a button so that when ever the button is pressed, the label updates the value of slider. The code is like this:

label.text = [NSString stringWithFormat:@"%f", slider.value]; 

It works, so now how do I make the label update the value as the slider is dragged?

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

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

发布评论

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

评论(1

月牙弯弯 2024-12-10 06:42:40

创建一个方法来处理值更改的情况,并将其添加为目标,如下所示:

[yourSlideReferenceVariable addTarget:self action:@selector(yourMethodNameGoesHere:) forControlEvents:UIControlEventValueChanged];

将方法签名定义为

-(void)yourMethodNameGoesHere:(id)sender{

}

如果您觉得在 Interface Builder 中执行此操作会更舒服,那么“值更改”就是您需要连接的事件你的 IBAction 方法。

Create a method to handle when value changed and add that as target as below:

[yourSlideReferenceVariable addTarget:self action:@selector(yourMethodNameGoesHere:) forControlEvents:UIControlEventValueChanged];

Define your method signature as

-(void)yourMethodNameGoesHere:(id)sender{

}

If you feel you would be more comfort doing this in Interface Builder, then 'value changed' is the event with which you need to hook up your IBAction method.

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