[英]UINavigationBar titleTextAttributes not updated after coming back from a View Controller
I'm using a UINavigationController
to display some view controllers. 我正在使用UINavigationController
来显示一些视图控制器。 I need to change the color of the navigation bar title every time I switch between two view controllers. 每次在两个视图控制器之间切换时,都需要更改导航栏标题的颜色。 This is what I'm doing now: 这就是我现在正在做的:
First View Controller 第一视图控制器
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBar.titleTextAttributes =
@{
NSForegroundColorAttributeName: [UIColor whiteColor],
NSFontAttributeName: [UIFont systemFontOfSize:14.0]
};
}
Second View Controller 第二视图控制器
- (void)viewDidLoad:(BOOL)animated
{
[super viewDidLoad:animated];
self.navigationController.navigationBar.titleTextAttributes =
@{
NSForegroundColorAttributeName: [UIColor blackColor],
NSFontAttributeName: [UIFont systemFontOfSize:14.0]
};
}
The first time I load First VC and when I push Second VC, the title color is handled correctly. 第一次加载First VC时,当我按Second VC时,标题颜色已正确处理。 The problem here is that when I pop from Second to First view controller, the title is still black, even if viewWillAppear
is called correctly and, if I print self.navigationController.navigationBar.titleTextAttributes
, the values seems to be updated ( NSForegroundColorAttributeName
is white). 这里的问题是,当我从第二个视图控制器弹出到第一个视图控制器时,即使正确调用了viewWillAppear
,标题仍然是黑色的;如果我打印self.navigationController.navigationBar.titleTextAttributes
,则值似乎已更新( NSForegroundColorAttributeName
为白色)。
Maybe because of the push/pop transition animation, values are not reflecting. 可能是由于推送/弹出过渡动画导致值未反映出来。 Try calling it this way. 尝试以这种方式调用它。
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
dispatch_async(dispatch_get_main_queue(), ^{
self.navigationController.navigationBar.titleTextAttributes =
@{
NSForegroundColorAttributeName: [UIColor blackColor],
NSFontAttributeName: [UIFont systemFontOfSize:14.0]
};
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.