开发者

Change a UILabels text with a UISliders value

开发者 https://www.devze.com 2023-02-15 18:25 出处:网络
How I could show a UISliders value as a U开发者_开发技巧ILabels text?Add an action to the slider, like this:

How I could show a UISliders value as a U开发者_开发技巧ILabels text?


Add an action to the slider, like this:

[slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];

Where the sliderChanged: method looks something like this:

- (void)sliderChanged:(UISlider *)slider {
    self.label.text = [NSString stringWithFormat:@"%g", slider.value];
}


Try this:

- (IBAction) sliderValueChanged:(UISlider *)sender {  
    label.text = [NSString stringWithFormat:@"%f", slider.value];
}  

If label and/or slider are IB elements, define IBOutlets and connect them.

And then connect the slider sliderChanged action to this method.

Good luck!


//This is for getting the Int Value

- (IBAction)sliderValueChanged:(UISlider *)sender 
{ 
  yourtextlabel.text =  [NSString stringWithFormat:@"%d", (int)yourslideroutletname.value];
NSLog(@"the selider value==%@",yourtextlabel.text);
 }

//This is for getting the float Value

- (IBAction)sliderValueChanged:(UISlider *)sender 
{ 
  yourtextlabel.text =  [NSString stringWithFormat:@"%f", yourslideroutletname.value];
NSLog(@"the selider value==%@",yourtextlabel.text);
 }
0

精彩评论

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