如何拥有动态(自动)更新滑块值的标签?
我的 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个方法来处理值更改的情况,并将其添加为目标,如下所示:
将方法签名定义为
如果您觉得在 Interface Builder 中执行此操作会更舒服,那么“值更改”就是您需要连接的事件你的 IBAction 方法。
Create a method to handle when value changed and add that as target as below:
Define your method signature as
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.