在iOS中导航条分为三块:leftView、titleView、rightView并且leftView和rightView是一样的
先说titleView
设置titleView为文字
self.title = @"购买大厅";
设置titleView为按钮
UIButton *titleBtn = [[UIButton alloc]init];
titleBtn.frame = CGRectMake(0, 0, 100, 44);
[titleBtn setTitle:@"合买订单" forState:UIControlStateNormal];
[titleBtn setImage:[UIImage imageNamed:@"YellowDownArrow"] forState:UIControlStateNormal];
[titleBtn addTarget:self action:@selector(titleBtnClike:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.titleView = titleBtn;
自定义titleView
UIView *customView = [[UIView alloc]init];
customView.frame = CGRectMake(0, 0, 200, 44);
customView.backgroundColor = [UIColor blueColor];
self.navigationItem.titleView = customView;
下面介绍如何设置LeftItem/RightItem
设置为文字
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"按钮" style:UIBarButtonItemStyleDone target:self action:nil];
设置为图片
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"Mylottery_config"] style:UIBarButtonItemStylePlain target:self action:nil];
设置为文字图片
UIButton *rightBtn = [[UIButton alloc]init];
rightBtn.frame = CGRectMake(0, 0, 100, 44);
[rightBtn setImage:[UIImage imageNamed:@"pushSettings"] forState:UIControlStateNormal];
[rightBtn setTitle:@"开奖信息" forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
自定义View
一般多个按钮就是创建按钮添加到自定义的View中的
UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
leftView.backgroundColor = [UIColor blueColor];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftView];
状态栏设置
在iOS7之前对状态条的操作是交由UIApplecation的,而在iOS7之后,对状态条的操作就交由了视图控制器来管理
在info.plist中添加View controller-based status bar appearance
设置为NO。这样UIAPPlication就可以控制状态条了。
启动隐藏状态条
方法一:
在info.plist中设置
方法二:
在TARGEST中勾选
隐藏状态栏
方法一:
//在视图控制器中写这个方法
- (BOOL)prefersStatusBarHidden
{
return YES;
}
方法二:
在UIAPPlication中添加
[[UIApplication sharedApplication] setStatusBarHidden: YES];//会报警告
改变状态条的颜色
状态条一共有三种样式
方法一:
可以在inf.plist中设置
方法二:
在UIApplication中
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];//setStatusBarStyle为枚举类型
注意如果状态栏隐藏掉那么状态栏的20px高度就算在了屏幕里面
如果想要状态栏有自定义效果,可以使用覆盖,也可以隐藏掉之后用UIView