开发者

setting a default value for slider when app loads

In my iPhone app I'm using a slider for adjusting the volume and working fine. But I'm not able to set a default value for slider when app loads. I have seen 开发者_运维问答that only when the slider is touched the value gets changed.But i need a default value when app loads. My code is given below

- (IBAction)sliderChanged:(id)sender {

    slider = (UISlider *) sender;
    slider.minimumValue = 0.5;
    slider.maximumValue = 2.2;
    progressAsInt = slider.value ;
}

how can i solve this issue.

please help.Thanks in advance.


There are two ways to change default value of slider.

  1. Using Interface builder. See attached picture and value of current property.

    setting a default value for slider when app loads

  2. Using Code

You just need to write this one line in viewWillAppear delegate method.

-(void)viewWillAppear:(BOOL)animated{
   slider.value = 1.0;
 }

Hope this help.


First you'll need to set the slider to an IBOutlet iVar of the view controller where the slider is.

Then, in the viewDidLoad of that view controller, you can set the value you want.

(Also, you should be able to do it in Interface Builder, but I'm not very familiar with it).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜