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];
}

一切都完美无缺。在我的应用程序中,我需要将一个视图控制器插入堆栈并弹出它。

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];

此时,标题栏失去了外观设置,回到了默认的白色。任何推入堆栈的新视图控制器也会失去其外观。

有什么问题?

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 回答