![](/img/trans.png)
[英]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.