简体   繁体   English

将屏幕的导航栏更改为黑色

[英]Changing navigation bar of screen to be black

I am learning objective-c and having some trouble making the top nav bar black. 我正在学习Objective-C,并且在使顶部导航栏变黑时遇到了一些麻烦。 Here's what I have so far: 这是我到目前为止的内容:

// AppDelegate.h
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navigationController;
@end

// AppDelegate.m
#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;  // optional
    return YES;
}

What am I doing wrong here / not understanding about this? 我在这里做错了/对此不了解? And how would this be fixed? 以及如何解决? Is it because I'm not synthesizing the navigationController? 是因为我没有合成navigationController吗? (when do you need to synthesize something?) (何时需要合成某些东西?)

try by setting the Tint 尝试通过设置Tint

[navbar setTint color:[uicolor blackColor]];

or 要么

navigationController.navigationBar.barTintColor = [UIColor greenColor]; navigationController.navigationBar.barTintColor = [UIColor greenColor];

This should be done in viewWillappear or didappear 应该在viewWillappear或didappear中完成

By default the UINavigationBar on an iOS app is blue. 默认情况下,iOS应用程序上的UINavigationBar为蓝色。 Apple have some built-in styles that you can use 苹果有一些内置样式可供您使用

[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackOpaque];

The options available are: 可用的选项有:

UIBarStyleBlack
UIBarStyleBlackOpaque
UIBarStyleBlackTranslucent
UIBarStyleDefault

UIBarStyleBlackOpaque and UIBarStyleTranslucent have been depreciated. UIBarStyleBlackOpaque和UIBarStyleTranslucent已弃用。 You should use UIBarStyleBlack and set property 'translucent' to yes if needed . 如果需要,您应该使用UIBarStyleBlack并将属性'translucent'设置为yes

You can also change the colour to any colour you wish using one of the two lines of codes below and adjusting the colour values. 您还可以使用以下两行代码之一将颜色更改为所需的任何颜色,并调整颜色值。

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.7 green:.5 blue:.2 alpha:1];


self.navigationController.navigationBar.tintColor = [UIColor blackColor];

If you are trying to make a application with a navigation controller stack it will usually look something like this. 如果您尝试使用导航控制器堆栈制作应用程序,则通常看起来像这样。

//Appdelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

//Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    MyCustomViewController *vc = [[MyCustomViewController alloc] init];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
    navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.window.rootViewController = navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}

使用这可能会有所帮助

self.navigationController.navigationBar.tintColor = [UIColor blackColor];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM