iOS 7导航栏SKStoreProductViewController

在iOS 6中,引入了SKStoreProductViewController以在应用程序中显示iTunes Store项目,因此用户不必离开应用程序即可查看它们。

到目前为止,我还没有find一种方法来定制此视图控制器的导航栏。 在iOS 6中,它是黑色的灰色文字,而在iOS 7中,它是白色的,黑色的文字。

有没有办法改变导航栏的色调? (在iOS 6和iOS 7中)

谢谢。

不是最好的解决scheme,但是您可以使用UINavigationBar的UIAppearance方法在显示之前设置颜色:

[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]]; SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewController alloc] init]; [storeProductViewController setDelegate:self]; [self presentViewController:storeProductViewController animated:YES completion:nil]; 

然后在SKStoreProductViewControllerDelegate方法中,将其更改回以前的任何内容…

 -(void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController { [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; [viewController dismissViewControllerAnimated:YES completion:nil]; } 

为我工作。

很不幸的是,不行。 SKStoreProductViewController是一个远程视图控制器 ,意味着它的视图完全由另一个进程拥有,并以编程方式无法访问。

这可以通过查看控制器视图的recursion描述来确认:

 <UIView: 0x8d48da0; frame = (0 0; 320 480); layer = <CALayer: 0x8d48d70>> | <_UISizeTrackingView: 0x9b53700; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x9b53770>> | | <_UIRemoteView: 0x9b51d70; frame = (0 0; 320 480); transform = [0.5, -0, 0, 0.5, -0, 0]; userInteractionEnabled = NO; layer = <CALayerHost: 0x9b55ae0>> 

_UIRemoteView指示视图的内容托pipe在另一个进程中。

我在Appirater的rateApp函数里面有这个问题,我这样解决了:

  //Use the in-app StoreKit view if available (iOS 6) and imported. This works in the simulator. if (!_openInAppStore && NSStringFromClass([SKStoreProductViewController class]) != nil) { SKStoreProductViewController *storeViewController = [[SKStoreProductViewController alloc] init]; storeViewController.delegate = self.sharedInstance; NSNumber *appId = [NSNumber numberWithInteger:_appId.integerValue]; [storeViewController loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:appId} completionBlock:^(BOOL result, NSError *error) { [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; id <AppiraterDelegate> delegate = self.sharedInstance.delegate; if ([delegate respondsToSelector:@selector(appiraterWillPresentModalView:animated:)]) { [delegate appiraterWillPresentModalView:self.sharedInstance animated:_usesAnimation]; } [[self getRootViewController] presentViewController:storeViewController animated:_usesAnimation completion:^{ [self setModalOpen:YES]; //Temporarily use a black status bar to match the StoreKit view. [self setStatusBarStyle:[UIApplication sharedApplication].statusBarStyle]; [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:_usesAnimation]; }]; }]; //Use the standard openUrl method if StoreKit is unavailable. } else { (...) 

您不能自定义栏的颜色,但其默认颜色看起来不错。 我发现我的UIAppearance设置正在改变文字颜色。

这是一个SKStoreProductViewController子类,它将条形文字的颜色设置为默认值,然后在解除时恢复你的UIAppearance设置。 如果您从代码中的多个位置展示,这很有用。

 @interface GBStoreProductViewController () { UIColor *navBarTintColor; NSDictionary *navBarTitleTextAttributes; } @end @implementation GBStoreProductViewController - (id)init { UIColor *tintColor = [[UINavigationBar appearance] tintColor]; NSDictionary *titleTextAttributes = [[UINavigationBar appearance] titleTextAttributes]; [[UINavigationBar appearance] setTintColor:nil]; [[UINavigationBar appearance] setTitleTextAttributes:nil]; if (self = [super init]) { navBarTintColor = tintColor; navBarTitleTextAttributes = titleTextAttributes; } return self; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[UINavigationBar appearance] setTintColor:navBarTintColor]; [[UINavigationBar appearance] setTitleTextAttributes:navBarTitleTextAttributes]; } @end 

对Kiran Panesar的技术感谢。

我也有这个问题,给出的appearance代码的答案不适合我。 我发现这是修复它,因为我更改了window.tintColor之前我的应用程序范围的window.tintColor

 [[UIApplication sharedApplication] keyWindow].tintColor = nil;