UISlider的用法

 UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(60, 100, 200, 20)];

    slider.tag = 101;

    slider.maximumValue = 10;

    slider.minimumValue = 0;


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

     [slider addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside];

    

    [slider addTarget:self action:@selector(test1) forControlEvents:UIControlEventTouchDragInside];

    [slider addTarget:self action:@selector(test2) forControlEvents:UIControlEventTouchDragOutside];

     [self.view addSubview:slider];

     [slider release];

    

    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test:) userInfo:slider repeats:NO];


//监听方法

- (void)change:(UISlider *)slider

{

    NSLog(@"slider value : %.2f", slider.value);

}


- (void)touchUpInside:(UISlider *)slider

{

    NSLog(@"touchUpInside : %.2f", slider.value);

}



- (void)test:(NSTimer *)timer

{

    UISlider *slider = [timer userInfo];

    [slider setValue:5 animated:NO];

}


- (void)test1

{

    NSLog(@"test1");

}


- (void)test2

{

    NSLog(@"test2");    

}




你可能感兴趣的:(UISlider的用法)