UISlider 滑动条

盖斌
2023-12-01
//滑块 音量设置,播放进度
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 30, 300, 50)];
    //滑块左边的颜色
    slider.minimumTrackTintColor = [UIColor redColor];
    //滑块右边的颜色
    slider.maximumTrackTintColor = [UIColor greenColor];

    UIImage *thumb = [UIImage imageNamed:@"round_30"];
    //设置滑块的图片
    [slider setThumbImage:thumb forState:UIControlStateNormal];
    [slider setThumbImage:thumb forState:UIControlStateHighlighted];


    //gitHubs
    //google-code
    //source-forge
    //stackoverflow
    //设置最大值和最小值
    slider.maximumValue = 100;
    slider.minimumValue = 0;

    //设置默认值
    slider.value = slider.maximumValue /  2;

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

- (void)change:(UISlider *)slider
{
    //获取当前进度
    float value = slider.value;
    NSLog(@"value = %f", value);
}
 类似资料: