如何从 UITextField 设置 UISlider 的值 [英] How to set value of UISlider from a UITextField

查看:28
本文介绍了如何从 UITextField 设置 UISlider 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Xcode 4.3,我希望能够使用 UITextField 编辑 UISlider 的值.我怎样才能做到这一点?我有一个在文本字段中显示其值的滑块,但我也可以从文本字段设置滑块的值吗?

I am using Xcode 4.3 and I want to be able to edit the value of a UISlider using a UITextField. How can I do this? I have a slider that displays its value in a text field, but can I also set the slider's value from a text field?

感谢您的帮助!!

推荐答案

假设textField"是你的文本字段的名称,我会在你的 viewDidLoad 方法中添加一个目标:

Assuming "textField" is the name of your text field, I would add a target to it in your viewDidLoad method:

[textField addTarget:self
              action:@selector(textFieldDidChange)
    forControlEvents:UIControlEventEditingChanged];

然后像你说的那样处理变化:

And then handle the change like you said:

- (void)textFieldDidChange {

    Slider.value = [[textfield.text] intValue];

}

希望这会有所帮助.

这篇关于如何从 UITextField 设置 UISlider 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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