//
// AppDelegate.m
// UI4_UIToolBar
//
// 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
// UI4_UIToolBar
//
// 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];
//每一个导航控制器都有一个导航栏
self.navigationController.toolbarHidden = NO;
// self.navigationController.toolbar.backgroundColor = [UIColor redColor];
// self.navigationController.toolbar.alpha = 0.5;
// self.navigationController.toolbar.tintColor = [UIColor redColor];
//设置背景图片
//导航栏(toolBar)的高度是44
[self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"toolBarImage@2x"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault]; 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]; UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(btnClicked:)]; UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(btnClicked:)];
item1.tag = 200; UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"导航" style:UIBarButtonItemStylePlain target:self action:@selector(btnClicked:)];
item2.tag = 201; UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(btnClicked:)];
item3.tag = 202; NSArray *items = [NSArray arrayWithObjects:space,item1,space,item2,space,item3,space,nil];
//定制toolbarItems按钮
self.toolbarItems = items; //UIButton + UIView
//自定义ToolBar
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
btn1.frame = CGRectMake(0, 0, 50, 44);
btn2.frame = CGRectMake(0, 0, 50, 44);
btn3.frame = CGRectMake(0, 0, 50, 44); [btn1 setBackgroundImage:[UIImage imageNamed:@"friend_add@2x"] forState:UIControlStateNormal];
[btn2 setBackgroundImage:[UIImage imageNamed:@"friend_qq@2x"] forState:UIControlStateNormal];
[btn3 setBackgroundImage:[UIImage imageNamed:@"friend_weixin@2x"] forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[btn2 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[btn3 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *item4 = [[UIBarButtonItem alloc] initWithCustomView:btn1];
UIBarButtonItem *item5 = [[UIBarButtonItem alloc] initWithCustomView:btn2];
UIBarButtonItem *item6 = [[UIBarButtonItem alloc] initWithCustomView:btn3]; NSArray *itemsArray = [NSArray arrayWithObjects:space,item4,space,item5,space,item6,space, nil];
self.toolbarItems = itemsArray;
} - (void)btnClicked:(UIButton *)btn
{
NSLog(@"按钮被点击");
} - (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
// UI4_UIToolBar
//
// Created by zhangxueming on 15/7/6.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SecondViewController.h" @interface SecondViewController () @end @implementation SecondViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor yellowColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

UI4_UIToolBar的更多相关文章

随机推荐

  1. 商户怎样选择商业wifi进行移动营销

    互联网移动营销的大潮席卷而来,带给很多其它的商户营销理念上的升级和更新.商业wifi营销成为很多其它的商户选择.以往,人们在咖啡店不过聊聊天喝喝咖啡,如今,人们能够更悠闲的歇息娱乐享受带有wifi的咖 ...

  2. js模板引擎介绍搜集

    js模板引擎越来越多的得到应用,如今已经出现了几十种js模板引擎,国内各大互联网公司也都开发了自己的js模板引擎(淘宝的kissy template,腾讯的artTemplate,百度的baiduTe ...

  3. IPC——消息队列

    Linux进程间通信——使用消息队列 下面来说说如何用不用消息队列来进行进程间的通信,消息队列与命名管道有很多相似之处.有关命名管道的更多内容可以参阅我的另一篇文章:Linux进程间通信——使用命名管 ...

  4. JavaScript跨域实现

    最近在做个上传文件的服务,其中包含一个上传的web页面.目的是想客户端页面嵌套这个web页面,然后直接将文件上传到服务器. 因为文件不同所以需要保存到的文件夹名称也不一样,所以客户端需要传递一个文件夹 ...

  5. IOS开发之路三(XML解析之KissXML的使用)

    最近再做一个项目需要用到xml的解析.今天查了一些资料自己做了一个小demo.纯OC没有界面.. 在IOS平台上进行XML文档的解析有很多种方法,在SDK里面有自带的解析方法,但是大多情况下都倾向于用 ...

  6. Creating Your Own Server: The Socket API, Part 1

    转:http://www.linuxforu.com/2011/08/creating-your-own-server-the-socket-api-part-1/ By Pankaj Tanwar  ...

  7. ubuntu 设置IP,设置网关

    1. 检验是否可以连通,就使用ping命令ping 网关 开始的时候总是现实unreachable 2. 设置IP sudo ifconfig eth0 133.133.133.190 netmask ...

  8. Youth(青春)

    Youth is not a time of life; it is a state of mind; it is not a matter of rosy cheeks, red lips and ...

  9. a letter and a number

    描述we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, ... f(Z) = 26, f(z) = -26;Give you a letter x ...

  10. MySQL(21):事务管理之 事务提交

    1. 现实生活中,许多操作都是需要用户确认的,例如用户删除一个文档,删除时候会弹出一个提示对话框,包含"确认"和"取消".同样的道理,在数据库中有些命令在使用的 ...