//
// 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. 【转】Delphi多线程学习(9):多线程数据库查询(ADO)

    原文:http://www.cnblogs.com/djcsch2001/articles/2382559.html ADO多线程数据库查询通常会出现3个问题: 1.CoInitialize 没有调用 ...

  2. ProgressCircular

    https://github.com/eltld/ProgressCircular

  3. 【JavaScript】AJAX总结(异步JavaScript和XML)

    AJAX介绍 通过 AJAX,你可以创建更好.更快以及更友好的 WEB 应用程序. AJAX 基于 JavaScript 和 JavaScript的XMLHttpRequest对象. AJAX 应用程 ...

  4. xcode中没有autoSizing的设置

    转自:http://blog.sina.com.cn/s/blog_954bb2f001016oyx.html 学习Xcode的iOS编程时,可能会发现Autosizing Control不见了,其原 ...

  5. 之前的Android项目报错,新建Android项目报错,代码中找不到错误解决方案

    打开一年前的东西,结果发现里面的android项目全部有个红叉,也找不到错误.新建一个项目也报错,首先确定自己的环境应该没问题,然后通过查看网上的资料,发现可能是debug的keystore到期啦. ...

  6. 基于css3的3D立方体旋转特效

    今天给大家分享一款基于css3的3D立方体旋转特效.这款特效适用浏览器:360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗. 不支持IE8及以下浏览器.效果图如下 : ...

  7. Java最重要的21个技术点和知识点之JAVA面向对象

    (二)Java最重要的21个技术点和知识点之JAVA面向对象  写这篇文章的目的是想总结一下自己这么多年JAVA培训的一些心得体会,主要是和一些java基础知识点相关的,所以也希望能分享给刚刚入门的J ...

  8. C. Ilya and Sticks

    C. Ilya and Sticks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. jq使用手册

    jq 使用手册   翻译整理:Young.J 官方网站:http://jquery.com    jQuery是一款同prototype一样优秀js开发库类,特别是对css和XPath的支持,使我们写 ...

  10. sqlserver数据库触发器和存储过程案例学习

      --创建表 create table zhuangzhan ( name ), code ) ); --往表添加一列 alter table zhuangzhan add descition in ...