3

ナビゲーション バー用に UIAppearance をセットアップしました。

[[UINavigationBar appearance] setTitleTextAttributes: [self navigationBarTitleTextAttributes]];



-(NSDictionary *)navigationBarTitleTextAttributes
{
    // UINavigationBar title
    NSNumber *navBarTitleShadowOpacity = [self.personalityDictionary objectForKey:kNavBarTitleShadowOpacity];
    UIColor *navBarTitleColor = [UIColor colorWithHexString: [self.personalityDictionary objectForKey:kNavBarTitleColor] alpha:1.0f];
    UIColor *navBarTitleShadowColor = [UIColor colorWithHexString:[self.personalityDictionary objectForKey:kNavBarTitleShadowColor] alpha: [navBarTitleShadowOpacity floatValue]];

    return [NSDictionary dictionaryWithObjectsAndKeys:
     navBarTitleColor, UITextAttributeTextColor,
     navBarTitleShadowColor, UITextAttributeTextShadowColor,
     [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
     nil];
}

すべてが完璧に機能します。アプリのある時点で、View Controller をスタックに挿入してポップする必要があります。

ChatsViewController* chatsViewController = [[ChatsViewController alloc] init];

NSMutableArray *mutableViewControllers = [self.navigationController.viewControllers mutableCopy];

[mutableViewControllers insertObject: chatsViewController atIndex: [mutableViewControllers count] - 1];

[self.navigationController setViewControllers: mutableViewControllers animated: NO];

[self.navigationController popToViewController: chatsViewController animated: YES];

この時点で、タイトル バーの外観設定が失われ、既定の白に戻ります。スタックにプッシュされた新しいView Controllerも外観を失います。

どうしたの?

4

1 に答える 1

-1

appDelegate クラスでこれをカスタマイズすると、この問題は発生しません。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
  {
   // Code.........

   [[UINavigationBar appearance] setTitleTextAttributes: [self navigationBarTitleTextAttributes]]
  }

-(NSDictionary *)navigationBarTitleTextAttributes
 {

// NSNumber *navBarTitleShadowOpacity = [self.personalityDictionary objectForKey:kNavBarTitleShadowOpacity];
 UIColor *navBarTitleColor = [UIColor redColor];//: [self.personalityDictionary objectForKey:kNavBarTitleColor] alpha:1.0f];
 UIColor *navBarTitleShadowColor = [UIColor  greenColor];//colorWithHexString:[self.personalityDictionary objectForKey:kNavBarTitleShadowColor] alpha: [navBarTitleShadowOpacity floatValue]];

return [NSDictionary dictionaryWithObjectsAndKeys:
        navBarTitleColor, UITextAttributeTextColor,
        navBarTitleShadowColor, UITextAttributeTextShadowColor,
        [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
        nil];
  } 

それがあなたを助けることを願っています。

于 2013-03-29T07:33:33.660 に答える