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的更多相关文章
随机推荐
- linux C 执行多个文件
- poj 1222 EXTENDED LIGHTS OUT(位运算+枚举)
http://poj.org/problem?id=1222 题意:给一个确定的5*6放入矩阵.每一个格子都有一个开关和一盏灯,0表示灯没亮,1表示灯亮着.让你输出一个5*6的矩阵ans[i][j], ...
- google对js延迟加载方案的建议
浏览器在执行JavaScript代码时会停止处理页面,当页面中有很多JavaScript文件或代码要加载时,将导致严重的延迟.尽管可以使用defer.异步或将JavaScript代码放到页面底部来延迟 ...
- 自己编写的.sh脚本文件运行完闪退解决方案
gnome-terminal设置如下图: 直接原因是,“命令退出时:退出终端”造成的!! 解决方案如下: 1. Ctrl + Alt + F1 ,进入文本操作模式: 2. 登录后,执行:yum ins ...
- Linux中的文件描述符与打开文件之间的关系
Linux中的文件描述符与打开文件之间的关系 导读 内核(kernel)利用文件描述符(file descriptor)来访问文件.文件描述符是非负整数.打开现存文件或新建文件时,内核会返回一个文件描 ...
- 项目源码--Android天气日历精致UI源码
下载源码 技术要点: 1. 天气日历精致UI 2. Android的Http通信技术 3. Android的天气信息解析 4. Android的日历信息的统计 5. Andorid的地理位置的管理 6 ...
- 【如何快速的开发一个完整的 iOS 直播 app】(美颜篇)
来源:袁峥Seemygo 链接:http://www.jianshu.com/p/4646894245ba 前言 在看这篇之前,如果您还不了解直播原理,请查看这篇文章如何快速的开发一个完整的iOS直播 ...
- leetcode题解:Binary Tree Postorder Traversal (二叉树的后序遍历)
题目: Given a binary tree, return the postorder traversal of its nodes' values. For example:Given bina ...
- css+div网页设计(二)--布局与定位
在网页设计中,能否控制好各个模块中在页面中的位置是非常关键的,与传统的表格定位不同,css+div定位方式更加的灵活,本篇博客将为大家介绍css+div的布局与定位. 一.盒子模型 由图可以看出 盒子 ...
- CSS/CSS3 如何实现元素水平居中
更新:可直接访问 [CSS/CSS3 如何实现元素水平居中] 查看效果,右键查看源代码 -------------------------------------------------分割线---- ...