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的更多相关文章
随机推荐
- android获取/更改gps和WIFI状态
一.WIFI状态的获取和更改 适用于 SDK1.0 , SDK1.5 1.获取WIFI状态 方法1:通过WifiManager进行操作 1WifiManager wifiManager = (Wifi ...
- Google Map和桌面组件 Android开发教程
本文节选于机械工业出版社推出的<Android应用开发揭秘>一 书,作者为杨丰盛.本书内容全面,详细讲解了Android框架.Android组件.用户界面开发.游戏开发.数据存储.多媒体开 ...
- 简单方便统一封装的傻瓜式GET/POST库AliasNet正式公布~开源喽~
在进行网页自动化时我们做得最多的工作就是不停的往某个URL GET/POST数据并得到相应的Response,通过分析Response的结果再进行下一步操作,通过网页自动化我们可以做很多工作,比如去某 ...
- HDU 4876 ZCC loves cards(暴力剪枝)
HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每一个卡片上有数字,如今选k个卡片,绕成一个环,每次能够再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个 ...
- 0c-36-自动释放池应用场景
.autorelease的应用场景 经常用来在类方法中快速创建1个对象. // 声明实现一个类方法 + (Student *)student { // 在里面直接进行autorelease retur ...
- QtInternal 之 高效使用QString
注意:本文翻译自 http://developer.qt.nokia.com 中的 UsingQStringEffectively ,中文译文见 简体中文版 ,如果你对翻译wiki感兴趣 ...
- A*算法解决八数码问题 Java语言实现
0X00 定义 首先要明确一下什么是A*算法和八数码问题? A*(A-Star)算法是一种静态路网中求解最短路径最有效的直接搜索方法也是一种启发性的算法,也是解决许多搜索问题的有效算法.算法中的距离估 ...
- 3.6html学习笔记之样式选择
1.元素选择器 *{padding:0;margin:0;} p,span{} 2.类选择器 *.class{} p.class{} <p class="important class ...
- SQL中VARCHAR与NVARCHAR存储区别
DATALENGTH 与LEN的查询区别 插入结果 总结:DATALENGTH计算字节长度,LEN计算字符串长度 VARCHAR(2)是指允许存取字节长度小于或等于2的字符串 NVA ...
- MVC框架 - 捆绑
捆绑和缩小是两个性能改进提高应用程序在请求负载时的技术.目前大多数的主流浏览器限制每个主机同时连接到六个数量.这意味着,在一个时间,所有的其他请求将被浏览器排队. 启用捆绑和缩小 为使捆绑和缩小MVC ...