我能以编程方式控制滑块值吗?

时间:2011-06-02 04:54:20

标签: iphone mpvolumeview

我使用了以下代码

for (UIView *view in [volumeView subviews]){
    if ([[[view class] description] isEqualToString:@"MPVolumeSlider"]) {
        volumeViewSlider = (UISlider *) view;
    }
}

//[volumeViewSlider setBackgroundColor:[UIColor colorWithRed:1.00 green:0.0 blue:0.0 alpha:1.0]];
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"leftslide.png"]
                            stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"rightslide.png"]
                             stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
//    [customSlider setThumbImage: [UIImage imageNamed:@"slider_ball.png"] forState:UIControlStateNormal];
[volumeViewSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[volumeViewSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
[volumeViewSlider setMinimumValueImage:[UIImage imageNamed:@"SpeakerSoft.tif"]];
[volumeViewSlider setMaximumValueImage:[UIImage imageNamed:@"SpeakerLoud.tif"]];


[NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(changeTheTimer) userInfo:nil repeats:NO];
}

-(void)changeTheTimer{
[volumeViewSlider setValue:0 animated:YES];
NSLog(@"Value is set to 0");

}

我想在一分钟后停止所有播放,但是滑块移动到零并且离开主音量效果,请帮助

1 个答案:

答案 0 :(得分:2)

您当然可以使用UISlider实例方法

- (void)setValue:(float)value animated:(BOOL)animated

这会在有或没有动画的情况下减小滑块值。

<强>更新

点击Controlling Master Volume

上的此链接