How to set value of UISlider from a UITextField

[亡魂溺海] 提交于 2019-12-06 12:37:18

问题


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?

Thanks for the help!!


回答1:


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

}

Hope this helps.



来源:https://stackoverflow.com/questions/11586948/how-to-set-value-of-uislider-from-a-uitextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!