self.view.backgroundColor = [UIColor cyanColor];
//设置标题 1 2
self.navigationItem.title = @"RootVC";
self.title=@"第一个控制器";
//创建一个button
UIButton * aButton = [UIButton setButtonWithFrame:CGRectMake(100, 550, 175, 40) title:@"进入下一界面" target:self action:@selector(handleButtonAction:)];
[self.view addSubview:aButton];
//__________________________________________
//给导航视图控制器设置左按钮
//System : 系统风格 custom自定义风格
UIBarButtonItem * leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(handleLeftBarButtonAction:)];
//给左边添加item
// self.navigationItem.leftBarButtonItem = leftBarButtonItem;
// [leftBarButtonItem release];
//练习 给导航视图控制器设置右按钮
UIBarButtonItem * rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(handleRightBarButtonAction:)];
//关键 给导航条设置右边按钮
// self.navigationItem.rightBarButtonItem = rightBarButtonItem;
// [rightBarButtonItem release];
//____________________________________
//自定义导航条左边的按钮样式以及响应方法
UIButton * leftButton = [UIButton setButtonWithFrame:CGRectMake(0, 0, 60, 30) title:@"阅读" target:self action:@selector(handleLeftButtionAction:)];
UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
self.navigationItem.leftBarButtonItems = @[leftBarButtonItem,leftItem];
// [leftBarButtonItem release];
// [leftItem release];
//注意:导航条摆放按钮和摆放标题的位置已经定义过.所以我们在自定义按钮或者自定义标题的时候只需设置大小即可,并且导航条允许一侧放置多个按钮
//自定义导航条右侧按钮
UIButton * rigthButton = [UIButton setButtonWithFrame:CGRectMake(0, 0, 60, 30) title:@"抢门票" target:self action:@selector(handleRigthButtonAction:)];
UIBarButtonItem * rigthItem = [[UIBarButtonItem alloc] initWithCustomView:rigthButton];
self.navigationItem.rightBarButtonItems = @[rightBarButtonItem,rigthItem];
// [rightBarButtonItem release];
// [rigthItem release];
//___________________________________
//自定义导航标题
UISegmentedControl * segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"会话",@"消息"]];
segmentedControl.frame = CGRectMake(0, 0, 80, 30);
// self.navigationItem.titleView = segmentedControl;
//设置导航条的其他属性
//1. 设置导航条的颜色(自身)
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
//2.设置导航条上面的控件的渲染颜色
self.navigationController.navigationBar.tintColor = [UIColor redColor];
//3.设置导航条是否隐藏 ,默认为NO ,表示不隐藏
//继承自UIView中的hidden属性
self.navigationController.navigationBar.hidden = NO;
//导航条特有的隐藏属性
self.navigationController.navigationBarHidden = NO;
[self.navigationController setNavigationBarHidden:NO animated:YES];
//4.设置导航条的半透明效果(毛玻璃),IOS7之后默认都是半透明效果,也就是YES
//以后再使用导航条时,不要随意更改透明状态,如果使用半透明效果,拿当前屏幕的 x,y会从(0,0)开始计算 ,如果 将导航条的半透明效果关闭(NO) 那当前屏幕的使用范围 就回向下移动64,也就是从 (0,64)开始计算
self.navigationController.navigationBar.translucent = YES;
//5.修改title的字号和颜色
self.title = @"演唱会";
self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor purpleColor]};
//6.为导航条添加图片
/*
竖屏情况下
1.如果图片的高度为64,图片正好正好铺满64高的导航条(包括状态栏也就是电池条)
2.如果图片的高度为44,图片将正好铺满44高的导航条,那高20的状态栏为黑色(此情况太丑,不经常用)
3.如果图片高度小于44,或者大于44小于64的话,会以原始图片的大小铺上之后在以此图片拼接成完整的64高度.
横屏状态:
只需要给定一个高32的图片即可,宽度较大.如果宽度不够会以此图片进行拼接.
[[UINavigationBar appearance] ]
*/
//竖屏
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forBarMetrics:UIBarMetricsDefault];
//横屏
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"2.jpg" ]forBarMetrics:UIBarMetricsCompact];
}
//- (UIStatusBarStyle)preferredStatusBarStyle {
// return UIStatusBarStyleLightContent;
//}
pragma Mark ---导航条响应事件
-(void)handleLeftBarButtonAction:(UIBarButtonItem *)sender{
NSLog(@"你你你点击了左按钮");
}
-(void)handleRightBarButtonAction:(UIBarButtonItem *)sender{
NSLog(@"你你你你点击了右按钮");
}
-(void)handleRigthButtonAction:(UIButton *)sender{
NSLog(@"嗯,抢票好难");
}
-(void)handleLeftButtionAction:(UIBarButtonItem *)sender{
NSLog(@"看小说,就看:这么慢,这么美");
}
pragma Mark --- 点击按钮 进入下一界面
-(void)handleButtonAction:(UIButton *)sender{
//创建secondVC对象
SecondViewController * secondVC = [[SecondViewController alloc] init];
//3 开始切换界面 把secondVC对象交给导航视图控制器管理
[self.navigationController pushViewController:secondVC animated:YES];
//4. 释放所有权
// [secondVC release];
}