【问题标题】:Change a UILabels text with a UISliders value使用 UISliders 值更改 UILabels 文本
【发布时间】:2011-03-10 03:18:07
【问题描述】:

如何将 UISliders 值显示为 UILabels 文本?

【问题讨论】:

    标签: cocoa-touch ios uilabel uislider


    【解决方案1】:

    向滑块添加一个动作,如下所示:

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

    sliderChanged: 方法如下所示:

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

    【讨论】:

      【解决方案2】:

      试试这个:

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

      如果标签和/或滑块是 IB 元素,定义 IBOutlets 并连接它们。

      然后将滑块sliderChanged 动作连接到此方法。

      祝你好运!

      【讨论】:

        【解决方案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);
         }
        

        【讨论】:

          猜你喜欢
          • 2016-09-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多