导航

//创建window

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];

//创建VC

ViewController *root = [[ViewController alloc] init];

//导航控制器 是管理控制器的控制器

//创建导航

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;

//创建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];

//修改导航栏上内容的颜色

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];

}

你可能感兴趣的:(导航)