开发者

UISlider Update UITextField - iPhone

开发者 https://www.devze.com 2023-03-27 23:34 出处:网络
I have a UISlider that I w开发者_如何学Pythonant to update a UITextField for the value of 1-100 in real time, i.e. I slide the slider and the value updates.

I have a UISlider that I w开发者_如何学Pythonant to update a UITextField for the value of 1-100 in real time, i.e. I slide the slider and the value updates.

How can I do this? I couldn't find anything in the class reference.


You will need to listen for value changes on the slider. You can set this up in interface builder or in code.

//Add event for valueChanged in viewDidLoad
[self.slider addTarget:self 
                action:@selector(sliderValueChanged:) 
      forControlEvents:UIControlEventValueChanged];

...

-(void)sliderValueChanged:(id)sender
{
    self.textField.text = [NSString stringWithFormat:@"%d", 
                             (int)(slider.value * 99) + 1];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消