6

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

到目前为止,我还没有找到自定义这个视图控制器的导航栏的方法。在 iOS 6 中为黑底灰字,在 iOS 7 中为白底黑字。

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

谢谢。

4

5 回答 5

7

不是最好的解决方案,但您可以使用 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];
}

为我工作。

于 2013-09-24T16:56:50.150 回答
5

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

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

<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表示视图的内容托管在另一个进程中。

于 2013-09-17T01:12:45.573 回答
2

我在 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 { (...)
于 2014-09-29T08:22:18.687 回答
1

您无法自定义栏的颜色,但其默认颜色看起来不错。我发现我的 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 的技术。

于 2013-12-10T20:07:35.547 回答
1

我也遇到了这个问题,并且为appearance代码给出的答案对我不起作用。我发现这是修复它的原因,因为我之前已经更改了我的应用程序window.tintColor范围appDelegate

[[UIApplication sharedApplication] keyWindow].tintColor = nil;
于 2017-11-10T00:26:46.967 回答