[英]Changing UINavigationBar titleTextAttributes inside view controller changing title color for entire UINavigationController
[英]UINavigationBar titleTextAttributes not updated after coming back from a View Controller
我正在使用UINavigationController
来显示一些视图控制器。 每次在两个视图控制器之间切换时,都需要更改导航栏标题的颜色。 这就是我现在正在做的:
第一视图控制器
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBar.titleTextAttributes =
@{
NSForegroundColorAttributeName: [UIColor whiteColor],
NSFontAttributeName: [UIFont systemFontOfSize:14.0]
};
}
第二视图控制器
- (void)viewDidLoad:(BOOL)animated
{
[super viewDidLoad:animated];
self.navigationController.navigationBar.titleTextAttributes =
@{
NSForegroundColorAttributeName: [UIColor blackColor],
NSFontAttributeName: [UIFont systemFontOfSize:14.0]
};
}
第一次加载First VC时,当我按Second VC时,标题颜色已正确处理。 这里的问题是,当我从第二个视图控制器弹出到第一个视图控制器时,即使正确调用了viewWillAppear
,标题仍然是黑色的;如果我打印self.navigationController.navigationBar.titleTextAttributes
,则值似乎已更新( NSForegroundColorAttributeName
为白色)。
可能是由于推送/弹出过渡动画导致值未反映出来。 尝试以这种方式调用它。
- (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.