iOS 7 Nav Bar SKStoreProductViewController

时间:2013-09-16 23:00:56

标签: ios objective-c app-store ios7

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

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

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

感谢。

5 个答案:

答案 0 :(得分: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];
}

适合我。

答案 1 :(得分:5)

不幸的是,没有。 SKStoreProductViewControllerremote view controller,意味着其视图完全由另一个进程拥有,并且无法以编程方式访问。

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

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

答案 2 :(得分: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 { (...)

答案 3 :(得分: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的技术的肯定。

答案 4 :(得分:1)

我也遇到了这个问题,而<?xml version="1.0" encoding="UTF-8"?> <!ELEMENT collection (storage)> <!ATTLIST collection xmlns CDATA #FIXED ''> <!ELEMENT storage (genre)+> <!ATTLIST storage xmlns CDATA #FIXED ''> <!ELEMENT genre (series)+> <!ATTLIST genre xmlns CDATA #FIXED '' domain CDATA #REQUIRED> <!ELEMENT series (title,author,number,country)> <!ATTLIST series xmlns CDATA #FIXED ''> <!ELEMENT title (#PCDATA)> <!ATTLIST title xmlns CDATA #FIXED ''> <!ELEMENT author (#PCDATA)> <!ATTLIST author xmlns CDATA #FIXED ''> <!ELEMENT number (#PCDATA)> <!ATTLIST number xmlns CDATA #FIXED ''> <!ELEMENT country (#PCDATA)> <!ATTLIST country xmlns CDATA #FIXED ''> <collection> <storage> <genre domain="horror"> <series> <title>The Walking Dead</title> <author>Frank Darabont</author> <number>1</number> <country>USA</country> </series> <series> <title>The Strain</title> <author>Guillermo del Toro</author> <number>11</number> <country>Canada</country> </series> <series> <title>Tales from the Crypt</title> <author>Bill Gaines</author> <number>12</number> <country>USA</country> </series> </genre> <genre domain="science fiction"> <series> <title>Stranger Things</title> <author>Duffer brothers</author> <number>4</number> <country>USA</country> </series> <series> <title>The 100</title> <author>Jason Rothenberg</author> <number>2</number> <country>USA</country> </series> <series> <title>The 4400</title> <author>Rene Echevarria</author> <number>3</number> <country>Canada</country> </series> <series> <title>The Twilight Zone</title> <author>Rod Serling</author> <number>5</number> <country>USA</country> </series> </genre> <genre domain="comedy"> <series> <title>Two and a Half Men</title> <author>Chuck Lorre</author> <number>6</number> <country>USA</country> </series> <series> <title>Anger Management</title> <author>Bruce Helford</author> <number>7</number> <country>USA</country> </series> <series> <title>Family Guy</title> <author>Seth MacFarlane</author> <number>8</number> <country>USA</country> </series> <series> <title>The Simpsons</title> <author>Matt Groening</author> <number>9</number> <country>USA</country> </series> </genre> <genre domain="drama"> <series> <title>House of Cards</title> <author>Beau Willimon</author> <number>13</number> <country>USA</country> </series> <series> <title>Riverdale</title> <author>Roberto Aguirre-Sacasa</author> <number>14</number> <country>Canada</country> </series> <series> <title>Supernatural</title> <author>Eric Kripke</author> <number>15</number> <country>USA</country> </series> </genre> </storage> </collection> 代码的答案对我来说并不适用。我发现这就是修复它的原因,因为我之前在appearance更改了我的应用范围window.tintColor

appDelegate