//
// AppDelegate.m
// UI3_UIbarButtonItem
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.window.rootViewController];
self.window.rootViewController = nav; return YES;
}
//
// ViewController.m
// UI3_UIbarButtonItem
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "SecondViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor cyanColor];
//每一个ViewController都对应一个NavigationItem对象
//设置标题
self.navigationItem.title = @"导航控制器";
//设置 self.title 默认把title的值赋值给navigationItem.title
self.title = @"导航导航"; NSLog(@"%@", self.navigationItem.title); UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100, 200, self.view.frame.size.width-200, 50);
[btn setTitle:@"点击" forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont boldSystemFontOfSize:24];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; } - (void)btnClicked
{
SecondViewController *svc =[[SecondViewController alloc] init];
[self.navigationController pushViewController:svc animated:YES];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//
// SecondViewController.m
// UI3_UIbarButtonItem
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SecondViewController.h" @interface SecondViewController () @end @implementation SecondViewController - (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"bar = %@", self.navigationController.navigationBar);
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor]; self.navigationItem.title = @"SecondView";
//设置提白后, navigationBar 的高度变为74
self.navigationItem.prompt = @"提白"; //设置标题视图 UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"musicTitle"]];
//设置标题视图 orgin坐标无效
imageView.frame = CGRectMake(0, 0, 20, 30);
self.navigationItem.titleView = imageView;
NSLog(@"imageView = %@", self.navigationItem.titleView); self.navigationItem.backBarButtonItem.title = @"返回";
NSLog(@"title = %@", self.navigationItem.backBarButtonItem.title); //初始化标题
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClicked)];
self.navigationItem.leftBarButtonItem = backButton;
//使用系统提供的样式
UIBarButtonItem *systemBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(systemBtnClicked)];
self.navigationItem.rightBarButtonItem = systemBtn;
//自定义UIBarButtonItem
UIButton *customBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[customBtn setBackgroundImage:[UIImage imageNamed:@"customImage@2x"] forState:UIControlStateNormal];
customBtn.frame = CGRectMake(0, 0, 22, 22);
[customBtn addTarget:self action:@selector(customBtnClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBtnItem = [[UIBarButtonItem alloc] initWithCustomView:customBtn]; NSArray *items = [NSArray arrayWithObjects:customBtnItem,systemBtn, nil];
self.navigationItem.rightBarButtonItems = items; UIBarButtonItem *editBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editBtnClicked)];
NSArray *leftItems = [NSArray arrayWithObjects:backButton,editBtn, nil];
self.navigationItem.leftBarButtonItems = leftItems;
} - (void)editBtnClicked
{
NSLog(@"编辑按钮被点击");
} - (void)backButtonClicked
{
[self.navigationController popViewControllerAnimated:YES];
} - (void)systemBtnClicked
{
NSLog(@"相机功能被点击");
} - (void)customBtnClicked
{
NSLog(@"自定义按钮被点击");
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end

UI3_UIbarButtonItem的更多相关文章

随机推荐

  1. 如何利用PhoneGap制作地图APP

    摘要:百度地图API是一套由javascript编写的地图程序接口,按说它应该运行在浏览器上.现在,只要利用PhoneGap,我们就能开发出移动平台上能使用的APP了! --------------- ...

  2. poj 3660 Cow Contest(传递闭包 Floyd)

    链接:poj 3660 题意:给定n头牛,以及某些牛之间的强弱关系.按强弱排序.求能确定名次的牛的数量 思路:对于某头牛,若比它强和比它弱的牛的数量为 n-1,则他的名次能够确定 #include&l ...

  3. sqlserver2008 复制,镜像,日志传输及故障转移集群区别

    一, 数据库复制 SQL Server 2008数据库复制是通过发布/订阅的机制进行多台服务器之间的数据同步,我们把它用于数据库的同步备份.这里的同步备份指的是备份服务器与主服务器进行 实时数据同步, ...

  4. WinServer 之 访问同网段服务器 或 同一服务器多虚拟机间的访问

    今天在发布网站时遇到不能访问同网段数据库服务器.具体情况为:web服务端部署在192.168.10.1下,而数据库服务端部署在192.168.10.2下,数据库连接直接配置为192.168.10.2会 ...

  5. go can't find import: "github.com/** 错误

    go get 后 go build 错误 can't find import: "github.com/ 原因: 1.gopath 没配好 2.go get 后要先 go install , ...

  6. C语言第七节流程控制

    流程控制 顺序结构:默认的流程结构.按照书写顺序执行每一条语句. 选择结构:对给定的条件进行判断,再根据判断结果来决定执行哪一段代码. 循环结构:在给定条件成立的情况下,反复执行某一段代码.     ...

  7. 【源码】初探C#爬虫,持续更新中。。。

       最近看到园子里有人用python做的爬虫软件并且上传的源码,苦于不懂python,便想着用C#也实现一个简易的爬虫软件.于是昨晚花了一个多小时的时间实现了一个简单的爬虫软件,功能十分简单,但是觉 ...

  8. Big String 块状数组(或者说平方分割)

    Big String 给一个字符串,长度不超过 106,有两种操作: 1. 在第 i 个字符的前面添加一个字符 ch 2. 查询第 k 个位置是什么字符 操作的总数不超过 2000 如果直接模拟的话, ...

  9. MySQL数据库还原:路径必须用正斜杠?

    也是术业不精,其实之前也用命令行还原过几次MySQL数据库,但总记不清语法.这不,今天想把另一台电脑上备份的数据库还原过来,结果不停报错,如下图所示: 后来才发现,因为偷懒直接复制的路径名里,用的全是 ...

  10. DataGridView 多线程更新 数据 解决卡顿问题

    使用多线程更新DataGridView,防止页面卡顿和卡死的问题 private delegate void UpdateDataGridView(DataTable dt); private voi ...