标签:
self.window.backgroundColor = [UIColor whiteColor];
//导航视图控制器也是一个视图控制器,TA管理了多个子视图控制器,是系统提供给我们的容器视图控制器。
//导航视图控制器至少管理一个子视图控制器,这个视图控制器称为导航视图控制器的根视图控制器
//如果我们的程序想要采用导航视图控制器进行布局,我们需要指定window的根视图控制器为导航视图控制器
RootViewController *rootVC = [[RootViewController alloc] init];
UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:rootVC];
//设置导航栏的显隐属性
naVC.navigationBarHidden = NO;
self.window.rootViewController = naVC;
//设置导航栏样式
naVC.navigationBar.barStyle = UIBarStyleDefault;
//设置导航条的背景颜色
naVC.navigationBar.backgroundColor = [UIColor greenColor];
//设置导航栏颜色
naVC.navigationBar.barTintColor = [UIColor greenColor];
//设置导航栏元素颜色
naVC.navigationBar.tintColor = [UIColor yellowColor];
[rootVC release];
[naVC release];
[self.window makeKeyAndVisible];
return YES;
}
#import "RootViewController.h"
@interface RootViewController ()
@end
@implementation RootViewController
- (void)leftAction {
self.view.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//每一个加到导航视图控制器内部的视图控制器自带一个属性叫navigationItem,可以配置当前页面导航条的显示内容,比如左、右按钮,标题等
self.navigationItem.title = @"中二洪荒";
//创建左按钮
/* 1 显示标题
UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithTitle:@"巴达" style:UIBarButtonItemStylePlain target:self action:@selector(leftAction)];*/
/* 2 使用系统自带图标样式
UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(leftAction)];*/
/* 3 使用自定义图片显示
UIImage *image = [UIImage imageNamed:@"dianhua"];
UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction)];
//指定左按钮
self.navigationItem.leftBarButtonItem = left;*/
/* 4 使用自定义视图显示
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithCustomView:mySwitch];
self.navigationItem.leftBarButtonItem = left;
[mySwitch release];
[left release];*/
//设置左、右按钮显示多个
UIBarButtonItem *first = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];
UIBarButtonItem *second = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(bookmark)];
self.navigationItem.rightBarButtonItems = @[first, second];
[first release];
[second release];
标签:
原文地址:http://www.cnblogs.com/wwww543623/p/5206725.html