gpt4 book ai didi

ios - iOS 中的导航栏更改为默认颜色,而不是设置为的颜色

转载 作者:行者123 更新时间:2023-11-28 20:06:24 25 4
gpt4 key购买 nike

在我实现访问地址簿的请求之前,我的导航栏被设置为某种颜色,但是一旦我实现了请求,导航栏的颜色就变成了默认的灰色。我尝试重新排列代码,但它不会显示地址簿请求。

- (void) displayMessage:(NSString *)paramMessage
{
[[[UIAlertView alloc] initWithTitle:nil
message:paramMessage
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Address book
CFErrorRef error = NULL;

switch (ABAddressBookGetAuthorizationStatus()){
case kABAuthorizationStatusAuthorized:{
addressBook = ABAddressBookCreateWithOptions(NULL, &error);
// Do your work and once you are finished ... //
if (addressBook != NULL){
CFRelease(addressBook);
}
break;
}
case kABAuthorizationStatusDenied:{
[self displayMessage:kDenied];
break;
}
case kABAuthorizationStatusNotDetermined:{
addressBook = ABAddressBookCreateWithOptions(NULL, &error);
ABAddressBookRequestAccessWithCompletion
(addressBook, ^(bool granted, CFErrorRef error) {
if (granted){
NSLog(@"Access was granted");
} else {
NSLog(@"Access was not granted");
}
if (addressBook != NULL){
CFRelease(addressBook);
}
});
break;
}
case kABAuthorizationStatusRestricted:{
[self displayMessage:kRestricted];
break;
}
}



//Assign tab bar item with titles
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];

tabBarItem1.title = @"Tab1";
tabBarItem2.title = @"Tab2";
tabBarItem3.title = @"Tab3";
tabBarItem4.title = @"Tab4";

[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"Tab1selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Tab1.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"Tab2selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Tab2.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"Tab3selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Tab3.png"]];
[tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"Tab4selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Tab4.png"]];
return YES;

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];

// Change the tab bar background
UIImage *tabBarBackground = [UIImage imageNamed:@"CustomUITabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:(106/255.0) green:(200/255.0) blue:(0/255.0) alpha:1]];

//Custom Navbar
UIImage *navbar = [UIImage imageNamed:@"navbar.png"];
[[UINavigationBar appearance] setBackgroundImage:navbar forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:textTitleOptions];
}

最佳答案

我在你的代码中间发现了return YES。返回代码放在设置导航栏外观的代码之前。我认为这就是您正在寻找的问题。将 return YES 放在方法的末尾。

而且,我发现了一个奇怪的点,看起来是一个不正常的用法。我猜你的根 viewcontroller 是一个 UITabBarController。但是, Root View Controller 被 return YES 后创建的 UINavigationController 覆盖。是故意的吗?

如果您想使用 UITabBarController 作为 Root View Controller ,请删除有关设置 UINavigationController 的代码。

关于ios - iOS 中的导航栏更改为默认颜色,而不是设置为的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21953880/

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