本文介绍了如何在标签中放置滑块值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 Xcode 很陌生,当滑块的值发生变化时,我无法将滑块的值放置在标签中.
I am quite new to Xcode and I am having trouble placing the value of a slider in a label when the slider is value is changed.
这是我的代码:头文件:
Here is my code:Header file:
@interface ViewTwoViewController : UIViewController
{
IBOutlet UISlider *slider;
IBOutlet UILabel *sliderLabel;
}
-(IBAction)sliderValue:(id)sender;
这是我的 m 文件:
-(IBAction)sliderValue:(UISlider *)sender {
sliderLabel.text = [NSString stringWithFormat:@"%g", slider.value];
}
我不是 100% 确定为什么值没有更新?
I am not 100% sure why the value isn't updating?
我期待收到大家的来信!
I am looking forward to hearing from you all!
推荐答案
这是一个 XCode 项目,可以满足您的需求:http://clrk.it/013r203C1y1F
Here's an XCode project that does what you're looking for: http://clrk.it/013r203C1y1F
注意:
- 标签和滑块连接到
UIViewController
作为故事板中的 IBOutlets. - 滑块的
valueChanged
: 方法链接到故事板中的UIViewController
. - 滑块的值使用
%f
显示.
- The label and slider are hooked up to the
UIViewController
asIBOutlets in the storyboard. - The slider's
valueChanged
: method is linked to theUIViewController
in the storyboard. - The slider's value is displayed using
%f
.
你的方法看起来像这样:
Your method would look something like this:
-(IBAction)sliderValueChanged:(id)sender
{
if (sender == _slider) {
_label.text = [NSString stringWithFormat:@"%0.3f", _slider.value];
}
}
这篇关于如何在标签中放置滑块值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!