UI3_UIbarButtonItem
//
// 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的更多相关文章
随机推荐
- MS WORD 表格自己主动调整列宽,自己主动变美丽,依据内容自己主动调整
在MS WORD中,当有大量的表格出现时,调整每一个表格的的高和宽和大小将是一件很累的事情,拖来拖去,很耗时间,并且当WORD文档达到300页以上时,调整反应很的慢,每次拖拉线后,须要等待一段时间其才 ...
- 微信公共服务平台开发(.Net 的实现)9-------处理二维码
今天我们来共同学习一下微信公共服务平台中一个重要内容---二维码扫描.众所周知二维码目前应用范围很广,在这里不再叙述背景了,但是值得一提的是目前大家手机上面应用的二维码扫描工具是支持的都是QR码和PD ...
- TP函数
U方法用于完成对URL地址的组装,特点在于可以自动根据当前的URL模式和设置生成对应的URL地址,格式为:U('地址','参数','伪静态','是否跳转','显示域名');在模板中使用U方法而不是固定 ...
- Linux服务器集群系统(三)--转
引用地址:http://www.linuxvirtualserver.org/zh/lvs3.html LVS集群中的IP负载均衡技术 章文嵩(wensong@linux-vs.org) 2002 年 ...
- Linux 命令 alternatives和update-alternatives
参考: http://lionbule.iteye.com/blog/717722 http://manpages.ubuntu.com/manpages/oneiric/man8/update-al ...
- C++实现日期转换类DateTime
概述 工作中我们在网络传输时使用time_t来传输时间,在显示时使用字符串来显示,下面是一个日期转换类的实现,方便以后使用: // DateTime.hpp #ifndef _DATETIME_H # ...
- docker 容器数据管理
给容器添加一个数据卷 sudo docker run -d -P --name web -v /webapp training/webapp python app.py 可以在Dockerfile中使 ...
- org.apache.hadoop.conf-Configured
org.apache.hadoop.conf中的最后一个类,也是这个包中以后用的最频繁的一个,Configurable算是肉体,Configuration算是灵魂吧 package org.apach ...
- iOS开发中添加PrefixHeader.pch要注意的问题
在Xcode6.0已经不默认生成PrefixHeader.pch文件了,而PrefixHeader.pch文件对我们开发带来的便利性是不言而喻的,所以我们怎么在工程中添加PrefixHeader.pc ...
- js数组的管理[增,删,改,查]
今天在设计表单的时候遇到对数组的一些处理的问题,比如说怎么创建一个数组,然后牵扯到数组的增删改查的方法.请看API FF: Firefox, N: Netscape, IE: Internet Exp ...