UINavigationController的使用心得(一)
来源:互联网 发布:python擅长做什么 编辑:程序博客网 时间:2024/05/02 04:56
同理与UITabBarController,一些普遍性的操作就不提到了,大家可以参考下(http://blog.csdn.net/totogo2010/article/details/7681879)的博客。
但是下面这幅图片还是得引用下:
根据网上的一些资料,自己做了一个demo,先上效果
以上的效果是很丑的(只是表达一个意思)。
首先使用到了MainViewController,FirstViewController两个视图。
先创建FirstViewController视图。
/// MainViewController.m
- (void)viewDidLoad
{
[superviewDidLoad];
//创建导航
FirstViewController *viewController = [[FirstViewControlleralloc] initWithNibName:nilbundle:nil];
viewController.title =@"firstViewController";
UINavigationController *navigationBar = [[UINavigationControlleralloc] init];
self.navigationController = navigationBar;
[navigationBar pushViewController:viewControlleranimated:YES];
[self.view addSubview:navigationBar.view];
[navigationBar release];
}1.NavigationBar的使用
首先在 MainViewController.h文件中
@property(strong,nonatomic)UINavigationController *navigationController;
在MainViewController.m 中
//1.设置navigationBar的文本颜色
self.navigationController.navigationBar.tintColor = [UIColorredColor];
//2.设置navigationBar的背景图片
UIImage *navBarImage = [UIImageimageNamed:@"bottomBK.png"];
UIImageView *imageView = [[UIImageViewalloc] initWithImage:navBarImage];
[self.navigationController.navigationBaraddSubview:imageView];
// 3.自定义设置navigationBar的背景图片 的方式(采用类目的方式)
参考 http://blog.csdn.net/zhuzhihai1988/article/details/7705308
在FirstViewController.m文件中
// 1.上面导航栏中的 左边按钮(系统)
UIBarButtonItem *leftButton = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCanceltarget:nilaction:@selector(leftButtonAction:)];
self.navigationItem.leftBarButtonItem = leftButton;
[leftButton release];
//2.上面导航栏中的 自定义左边按钮
UIBarButtonItem *coutomButton = [[UIBarButtonItemalloc] initWithTitle:@"asdfasdf"style:UIBarButtonItemStyleDone target:self action:@selector(rightButtonAction1:)];
UIButton *button11 = [UIButtonbuttonWithType:UIButtonTypeCustom];
[button11 setFrame:CGRectMake(0,0, 40, 30)];
[button11 setBackgroundColor:[UIColorredColor]];
[button11 setBackgroundImage:[UIImageimageNamed:@"102.png"]forState:UIControlStateNormal];
[button11 setBackgroundImage:[UIImageimageNamed:@"102-sel.png"]forState:UIControlStateHighlighted];
coutomButton.customView = button11;
[button11 release];
self.navigationItem.leftBarButtonItem = coutomButton;
[coutomButton release];
//3.自定义中间titleView
UIButton *titleButton = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
titleButton.frame = CGRectMake(0,0, 40, 30);
[titleButton setBackgroundColor:[UIColorwhiteColor]];
[titleButton setTitle:@"titlView"forState:UIControlStateNormal];
self.navigationItem.titleView = titleButton;
[titleButton release];
// 4.上面导航栏中的右边按钮(系统)
UIBarButtonItem *rightButton = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemComposetarget:selfaction:@selector(rightButtonAction1:)];
self.navigationItem.rightBarButtonItems = [NSArrayarrayWithObjects:rightButton, nil];
[rightButton release];
注意事项:
Navigationbar 的位置坐标和宽度,高度是修改不了的。 即bar.frame = CGRectMake(0,20,self.view.bounds.size.width,30);重新设置navigationbar是不起作用的。
2.NavigationToolBar的使用
在MainViewController.m文件中//1.显示底部工具栏
self.navigationController.toolbarHidden =NO;
//2.设置底部工具栏的背景图片
UIImage *navBarImage11 = [UIImageimageNamed:@"bottomBK.png"];
UIImageView *imageView11 = [[UIImageViewalloc] initWithImage:navBarImage11];
[self.navigationController.toolbaraddSubview:imageView11];
//3.设置底部工具栏的文本颜色
self.navigationController.toolbar.tintColor = [UIColorredColor];
//4.两个自定义tool下的按钮和系统save按钮
UIBarButtonItem *custom = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearchtarget:nilaction:nil];
UIButton *button3 = [[UIButtonalloc] initWithFrame:CGRectMake(0,0, 60,44)];
[button3 setBackgroundImage:[UIImageimageNamed:@"102.png"]forState:UIControlStateNormal];
custom.customView = button3;
UIBarButtonItem *add = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAddtarget:nilaction:nil];
UIButton *button4 = [[UIButtonalloc] initWithFrame:CGRectMake(0,0, 60,44)];
[button4 setBackgroundImage:[UIImageimageNamed:@"102.png"]forState:UIControlStateNormal];
add.customView = button4;
UIBarButtonItem *save = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSavetarget:nilaction:nil];
UIBarButtonItem *save3 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSavetarget:nilaction:nil];
UIBarButtonItem *save1 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSavetarget:nilaction:nil];
UIBarButtonItem *save2 = [[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSavetarget:nilaction:nil];
self.toolbarItems = [NSArrayarrayWithObjects:custom,add,save,save1,save2,save3,nil];
[button3 release];
[button4 release];
[custom release];
[add release];
[save release];
[save1 release];
[save2 release];
[save3 release];
注意事项:
NavigationToolbar 的位置坐标和宽度同NavigationBar的一样不能修改的。
- UINavigationController的使用心得(一)
- 我使用Castor的心得(一)
- c++11的使用心得(一)
- UINavigationController讲解(一)
- UINavigationController详解与使用(一)
- UINavigationController的使用
- UINavigationController的使用技巧
- UINavigationController的使用
- UiNavigationController的使用
- UINavigationController,UITableview的使用
- UINavigationController的使用
- UINavigationController 的使用
- IOS的UINavigationController使用
- FragmentStack的使用心得一
- sqlapi 使用心得(一)
- VB使用心得(一)
- ARC使用心得(一)
- ARC使用心得(一)
- 中断子系统(3)8259A中断控制器
- 第二学期第四周项目1--三角形类1
- WindowsAPI详解——获得进程可执行文件路径的几种方法
- 不安装Oracle客户端使用PLSQL
- Atlas源码剖析(五)
- UINavigationController的使用心得(一)
- Java中try catch finally语句中含有return语句的执行情况
- Oracle 数据库 10g:为 DBA 提供的 20 个最重要的特性 - 15.段管理
- ffmpeg: error while loading shared libraries: libavdevice.so.53
- ubuntu安装流媒体服务器Darwin Streaming Server
- 浙大05机试A + B
- fseek函数
- 设计模式学习之——六大设计原则之三:依赖倒置原则
- Java容器分析--Map