在UITableViewController中设置导航栏颜色。

时间:2014-04-06 06:31:42

标签: ios uinavigationcontroller uitableview

我有一个相当简单的应用程序UITableViewControllerUINavigationController

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    OverviewTableViewController *overview = [[OverviewTableViewController alloc] initWithNibName:@"OverviewTableViewController" bundle:nil];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:overview];

    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];

    return YES;
}

在我的OverviewTableViewController中,我尝试为这样的导航栏设置颜色,但似乎无法正常工作

self.navigationController.navigationBar.tintColor = [UIColor blueColor];
self.navigationController.navigationBar.translucent = TRUE;

我知道我可以在didFinishLaunchingWithOptions这样做:

nav.navigationBar.tintColor = [UIColor blueColor];
nav.navigationBar.barTintColor = [UIColor blueColor];
nav.navigationBar.translucent = YES;

我如何在UITableViewController

中执行此操作

2 个答案:

答案 0 :(得分:2)

OverviewTableViewController的viewDidLoad

 - (void)viewDidLoad
    {
        [super viewDidLoad];

        UIColor *bg = [UIColor blueColor];
        [self.navigationController.navigationBar setBarTintColor:bg];
        [self.navigationController.navigationBar setTranslucent:YES];
        [self.navigationController.navigationBar setBarStyle:UIBarStyleBlack]
    }

答案 1 :(得分:0)

OverviewTableViewController中,您可以使用self.navigationController来引用navigationController。

所以,你可以使用下面的代码。

UINavigationController *nav = self.navigationController;
nav.navigationBar.tintColor = [UIColor blueColor];
nav.navigationBar.barTintColor = [UIColor blueColor];
nav.navigationBar.translucent = YES;