IOS 7 Nav Bar SKStoreProductViewController

In iOS 6, the SKStoreProductViewController was introduced to display iTunes Store items in applications, so the user did not need to leave the application for viewing.

So far, I have not found a way to customize the navigation bar of this view controller. In iOS 6 it is black with a gray recording, and in iOS 7 it is white with a black recording.

Can I change the hue of the navigation bar? (On iOS 6 and iOS 7)

Thanks.

+6
source share
5 answers

Not the nicest solution, but you can use the UINavigationBar UIAppearance to set the color just before displaying it:

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

And then in the SKStoreProductViewControllerDelegate method change it to what it was before ...

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

It works for me.

+7
source

Unfortunately not. SKStoreProductViewController is a remote viewing controller , that is, its view belongs entirely to another process and is not available programmatically.

This can be confirmed by looking at the recursive description of the controller view:

 <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 indicates that the contents of the view are hosted in another process.

+5
source

I had this problem inside the Appirater rateApp function, I fixed it as follows:

  //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 { (...) 
+2
source

You cannot adjust the color of the bar, but its default colors look great. I found that my UIAppearance settings change the color of the text.

Here is a subclass of SKStoreProductViewController that sets the color of the stroke text to default and then restores the UIAppearance settings when fired. Useful if you represent from several places in your code.

 @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 

Loans to Kieran Panesaru for equipment.

+1
source

I had this problem too, and the answers for appearance code didn't work for me. I found that this is what is fixed because I changed my window.tintColor in the window.tintColor application in appDelegate before:

 [[UIApplication sharedApplication] keyWindow].tintColor = nil; 
+1
source

Source: https://habr.com/ru/post/953950/


All Articles