iOS - MPMediaPickerController - 更改barStyle

时间:2011-09-05 19:03:31

标签: iphone ios cocoa-touch ios5

我到处寻找,似乎无法找到有效的解决方案......

我正在开发一个使用MPMediaPickerController的应用程序并创建一个Modal视图,允许用户选择要播放的歌曲。我的主视图有一个blackOpaque barStyle,我希望Picker有相同的,但我似乎无法改变barStyle或颜色,无论如何我尝试过。以下是代码段:

-(IBAction)showMediaBrowser:(id)sender  {
// Create a MediaPickerController object (alloc) and initialize with ONLY music type media
mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];

// CK - Set properties
mediaPicker.delegate = self;
mediaPicker.prompt = @"Choose your song:";
mediaPicker.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque;

// CK - Present the model view and animate
[self presentModalViewController:mediaPicker animated:YES]; }

由于

1 个答案:

答案 0 :(得分:3)

可能(可能)媒体选择器在您尝试设置工具栏样式的时间点没有导航工具栏。您是否检查过mediaPicker.navigationController是否有值?

我建议将媒体选择器控制器嵌入到您自己的视图层次结构中(docs for MPMediaPickerController表示可以),然后您就可以从自己的视图控制器完全控制导航栏。

// create media picker controller
mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];

// set properties
mediaPicker.delegate = self;
mediaPicker.prompt = @"Choose your song:";

// get the media picker's view and set its frame
UIView *pickerView = mediaPicker.view;
pickerView.frame = myViewController.view.frame;

// add the media picker view to the view hierarchy
[myViewController.view addSubview:pickerView];