views:

27

answers:

1

How can I create and display a UISlider programmatically and display it. I found the code below in Apple documentation and added it to my viewDidLoad method but the slider doesn't appears when I run the code.

CGRect frame = CGRectMake(0.0, 0.0, 200.0, 10.0);
    UISlider *slider = [[UISlider alloc] initWithFrame:frame];
    [slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    [slider setBackgroundColor:[UIColor clearColor]];
    slider.minimumValue = 0.0;
    slider.maximumValue = 50.0;
    slider.continuous = YES;
    slider.value = 25.0;
+1  A: 

You need to add the slider into your view hierarchy. Add [self.view addSubview:slider]; and it should work.

Michal
great thanks!! It works
cgossain