AppDelegate.m
先创建一个ViewController
MainViewController *mainVC = [[MainViewController alloc]init];
创建导航视图控制器(用于管理 mainVC)
UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:mainVC];
self.window.rootViewController = naVC;
释放
[mainVC release];
[naVC release];
UINavigationController的基本设置
(1).加标题
self.title = @"猫眼儿电影";
或者
self.navigationItem.title = @"鹰王电影";
背景颜色的设置
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
注意不是所有的背景颜色都是backgroundColor
为了防止坐标系被篡改,我么办吧bar从半透明设置成不透明,这样坐标系的原点会自动向下推64
self.navigationController.navigationBar.translucent = NO;
内容方面的设置,可以指定一些视图称为titleview
UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:@[@"信息", @"通话", @"网络"]];
self.navigationItem.titleView = seg;
创建左右两边的按钮
左边(添加的是系统自带的图标)
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(laftButtonAction:)] autorelease别忘了释放];
右边 添加自定义图标 (阿里巴巴图标库 调整为大小32 格式PNG)**********
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rigth:)];
同时
可以添加一个自己创建的Button
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(0, 0, 40, 40);
[button1 setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button1];