Hey guys i was wondering how i could show a UISliders value as a UILabels text. Thanks
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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]; } 回答2:
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!
回答3:
//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); }