//創(chuàng)建window
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//創(chuàng)建VC
ViewController *root = [[ViewController alloc] init];
//導航控制器 是管理控制器的控制器
//創(chuàng)建導航
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:root];
//把導航設置為跟視圖
self.window.rootViewController = nav;
[nav release];
[root release];
[_window release];
return YES;
}
//? ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
//導航欄設置: controller(欄)/item(欄上的元素)
//導航欄顯示/隱藏
self.navigationController.navigationBarHidden = NO;
//? ? self.navigationController.navigationBar.hidden = YES;
//欄樣式
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
//半透明效果
//開啟效果時 屏幕左上角為坐標原點
//關閉時? 導航欄左下角為坐標原點
self.navigationController.navigationBar.translucent = YES;
//創(chuàng)建View(0, 0,100, 100)
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
view.backgroundColor = [UIColor yellowColor];
[self.view addSubview:view];
[view release];
//欄背景顏色
self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];
//欄顏色
self.navigationController.navigationBar.barTintColor = [UIColor grayColor];
// 欄標題
//? ? self.title = @"這是一個標題";
self.navigationItem.title = @"這是一個猴賽雷的標題";
//分段控制器
UISegmentedControl *seg = [[[UISegmentedControl alloc] initWithItems:@[@"消息",@"電話"]] autorelease];
seg.frame = CGRectMake(100, 100, 100, 30);
//欄標題視圖
self.navigationItem.titleView = seg;
//欄左側按鈕
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(left:)] autorelease];
//欄右側按鈕
UIBarButtonItem *b1 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(right1)] autorelease];
UIBarButtonItem *b2 = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"1.png"] style:UIBarButtonItemStylePlain target:self action:@selector(right2)] autorelease];
self.navigationItem.rightBarButtonItems = @[b1,b2];
//修改導航欄上內(nèi)容的顏色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
//跳轉頁面
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(200, 200, 100, 100);
btn.backgroundColor = [UIColor blackColor];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(goTwo) forControlEvents:UIControlEventTouchUpInside];
}