Change a UILabels text with a UISliders value

匿名 (未验证) 提交于 2019-12-03 02:27:02

问题:

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);  } 


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