IOS笔记之UIKit_UINavigationController
//设置导航条的样式
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
//默认是白色 Bar 字体颜色黑色,如果样式设置黑色,对应的字体就是白色。
//定义导航条的时候使用
self.navigationController.navigationBar.translucent = YES;
//设置导航条的背景颜色
self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
//也可以是一张图
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"back.png"] forBarMetrics:UIBarMetricsDefault];
//设置裁剪属性 44 超出的部分减掉
self.navigationController.navigationBar.clipsToBounds = YES;
//左侧item
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(barButtonClick:)];
//设置唯一的标签
leftButton.tag = 101;
//添加到导航条上
self.navigationItem.leftBarButtonItem = leftButton;
//添加一个右侧的按钮
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward target:self action:@selector(barButtonClick:)];
rightButton.tag = 102;
self.navigationItem.rightBarButtonItem = rightButton;
//设置navigationItem的标题
self.navigationItem.title = @"我的歌声里";
//设置副标题
self.navigationItem.prompt = @"曲婉婷";
//再创建一个UIBarButtonItem类型的按钮
UIBarButtonItem *leftButton1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPause target:self action:@selector(barButtonClick:)];
//设置左视图(多个按钮)
NSArray *leftBarButtonArray = @[leftButton,leftButton1];
//把这个数组设置给自动扩展位置 navigationItem.leftBarButtonItems 属性
self.navigationItem.leftBarButtonItems = leftBarButtonArray;
//自定义UINavigationItem的titleView
UIView *newTilteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 44)];
newTilteView.backgroundColor = [UIColor redColor];
//添加到父视图上
self.navigationItem.titleView = newTilteView;
//如果MRC 考虑内存管理
#pragma mark - 显示ToolBar工具条
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//默认 YES 隐藏的,NO 显示出来的
self.navigationController.toolbarHidden = NO;
//设置工具条的样式
self.navigationController.toolbar.barStyle = UIBarStyleBlack;
//因为iOS7系统默认开启了透明选项
self.navigationController.toolbar.translucent = YES;
//给工具条添加按钮 1...多个 UIBarButtonItem
UIBarButtonItem *btn1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(btnClick:)];
btn1.tag = 103;
//创建按钮2
UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(btnClick:)];
btn2.tag = 104;
//给btn1 弹簧 btn2
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
//添加到工具条上
NSArray *toolArray = @[btn1,space,btn2];
//显示按钮
self.toolbarItems = toolArray;
}
//页面跳转(下一界面)
[self.navigationController pushViewController:svc animated:YES];
//返回上一界面
[self.navigationController popViewControllerAnimated:YES];
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。