在MPMoviePlayerViewController中自定义两个UISliders?

时间:2013-06-14 07:45:19

标签: ios objective-c uislider uiappearance

我目前正在尝试在MPMoviePlayerViewController中自定义一些内容,但我在使用其中一个滑块时出现问题。

如下所示,它具有2个滑块,一个音量滑块和一个小持续时间滑块。

使用以下内容:UIImage *thumbImage = [UIImage imageNamed:@"MPThumbSelected.png"]; [[UISlider appearance] setThumbImage:thumbImage forState:UIControlStateNormal];

我可以自定义每个滑块,包括音量滑块,但由于某种原因,导航栏中较小的滑块不会更新。有没有人有什么建议?任何帮助将不胜感激!谢谢!!

enter image description here

1 个答案:

答案 0 :(得分:6)

您可以更改MPMoviePlayerController的默认控件。您可以做的一件事是您可以隐藏MPMoviePlayerViewController的默认控件并添加自己的自定义音量滑块。

moviePlayer.controlStyle=MPMovieControlStyleNone;

您可以像这样添加音量按钮:

UIButton *soundBtn=[ UIButton buttonWithType:UIButtonTypeCustom];
    soundBtn.frame=CGRectMake(400,10,35,35);
    soundBtn.showsTouchWhenHighlighted=YES;
    [soundBtn setBackgroundImage:[UIImage imageNamed:@"valume.png"] forState:UIControlStateNormal];
    [soundBtn addTarget:self action:@selector(valumeAction) forControlEvents:UIControlEventTouchUpInside];
    [controllsView addSubview:soundBtn];

对于Volume,您可以使用MPVolumeView类

-(void)volumeController{
    volumeView = [[UIView alloc]initWithFrame:CGRectMake(40,410,100,20)];
    volumeView.backgroundColor = [UIColor clearColor];

    [self.view addSubview:volumeView];

    //MP Valume Slider for controlling thew volume
    volumeslider = [[[MPVolumeView alloc] initWithFrame:volumeView.bounds] autorelease];
    NSArray *tempArray = volumeslider.subviews;
    for (id current in tempArray){
        if ([current isKindOfClass:[UISlider class]]){
            UISlider *tempSlider = (UISlider *) current;
            UIImage *stetchLeftTrack = [[UIImage imageNamed:@"bar_2.png"]
                                        stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];
            UIImage *stetchRightTrack = [[UIImage imageNamed:@"bar.png"]
                                         stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];
            [tempSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
            [tempSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
        } 
    } 
    [volumeView addSubview:volumeslider];
    //[controllsView addSubview:volumeView];
    [volumeView sizeToFit];
    volumeView.hidden = YES;
    isValumeBarHidden = YES;
    //Volume Slider created and added to the volumeview
}