gpt4 book ai didi

ios - iPhone 导航栏标题文本颜色在 iOS 11 中的 viewWillAppear() 或 viewWillDisappear 函数中不会改变

转载 作者:可可西里 更新时间:2023-11-01 03:44:58 25 4
gpt4 key购买 nike

错误在 iOS 10 中没有发生。标题文本颜色的默认值是黑色,当导航到新屏幕 (2) 时,我在 viewWillAppear() 中将标题文本颜色更改为粉红色,在 viewWillDisappear 中我将其更改为默认颜色。逻辑在 iOS 10 上没问题,但在 iOS 11 上,第一个带有栏标题颜色的屏幕是粉红色(预期是默认颜色)

此外:当在 viewWillAppear() 中添加逻辑改变颜色时(在这种情况下颜色不会改变)但是 这在 viewDidAppear() 中有效,但是有错误,标题是闪烁变化从屏幕 2 返回屏幕 1 时的颜色

屏幕 2 中的源代码(适用于 iOS 10):

#define NAVBAR_TITLE_FONT_ATTR @{ UITextAttributeFont : [UIFont boldSystemFontOfSize:19], UITextAttributeTextColor: [UIColor colorWithRed:9/255.0 green:34/255.0 blue:83/255.0 alpha:1]}
#define NAVBAR_TINT_COLOR [UIColor colorWithRed:97/255.0 green:113/255.0 blue:146/255.0 alpha:1]
#define NAVBAR_BG_COLOR [UIColor colorWithRed:247/255.0 green:247/255.0 blue:247/255.0 alpha:1]
#define LIGHT_BLUE_COLOR [UIColor colorWithRed:0.04 green:0.13 blue:0.33 alpha:1.0]


-(void)viewWillAppear:(BOOL)animated {

[super viewWillAppear:animated];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
textColor = [UIColor pinkColor]
self.navigationController.navigationBar.tintColor = textColor;
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
textColor, NSForegroundColorAttributeName,
[UIFont boldSystemFontOfSize:19], NSFontAttributeName,nil];

}

-(void)viewWillDisappear:(BOOL)animated {

[super viewWillDisappear:animated];

self.navigationController.navigationBar.tintColor = NAVBAR_TINT_COLOR;
self.navigationController.navigationBar.barTintColor = NAVBAR_BG_COLOR;
self.navigationController.navigationBar.translucent = NO;
[self.navigationController.navigationBar setTitleTextAttributes:NAVBAR_TITLE_FONT_ATTR];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}

screen 1

screen 2

come back screen 1

正确答案是:

- (void)willMoveToParentViewController:(UIViewController *)parent {

if (!parent) {
self.navigationController.navigationBar.titleTextAttributes = @{
NSForegroundColorAttributeName: [UIColor blackColor]
};

}

}

谢谢@Phu Nguyen

Detecting when the 'back' button is pressed on a navbar

最佳答案

你在第二个 View Controller 中试过这个吗?

- (void)willMoveToParentViewController:(UIViewController *)parent {
[super willMoveToParentViewController:parent];
NSLog(@"Parent view controller: %@", parent);
if (!parent) {
self.navigationController.navigationBar.titleTextAttributes = @{
NSForegroundColorAttributeName: [UIColor blackColor]
};
}
}

enter image description here

关于ios - iPhone 导航栏标题文本颜色在 iOS 11 中的 viewWillAppear() 或 viewWillDisappear 函数中不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48055555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com