如何在标签中放置滑块值? [英] How do I place a slider value in label?

查看:22
本文介绍了如何在标签中放置滑块值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 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

注意:

  1. 标签和滑块连接到 UIViewController 作为故事板中的 IBOutlets.
  2. 滑块的 valueChanged: 方法链接到故事板中的 UIViewController.
  3. 滑块的值使用 %f 显示.
  1. The label and slider are hooked up to the UIViewController as IBOutlets in the storyboard.
  2. The slider's valueChanged: method is linked to the UIViewController in the storyboard.
  3. 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];
    }

}

这篇关于如何在标签中放置滑块值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆