//
// 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. FluorineFx 播放FLV 时堆棧溢出解决 FluorineFx NetStream.play 并发时,无法全部连接成功的解决办法

    http://25swf.blogbus.com/tag/FluorineFx/ http://www.doc88.com/p-7002019966618.html  基于Red5的视频监控系统的研究 ...

  2. TP复习3

    ## ThinkPHP 3.1.2 CURD特性#讲师:赵桐正微博:http://weibo.com/zhaotongzheng 本节课大纲: 一.ThinkPHP 3 的CURD介绍 (了解) 二. ...

  3. oc-32-@property示例

    Goods.h #import <Foundation/Foundation.h> typedef struct{ int year; int month; int day; } MyDa ...

  4. C++ Qt 访问权限总结

    总结:C++的访问修饰符的作用是以类为单位,而不是以对象为单位. 通俗的讲,同类的对象间可以“互相访问”对方的数据成员,只不过访问途径不是直接访问. 步骤是:通过一个对象调用其public成员函数,此 ...

  5. 解决vim中鼠标右键无法复制的问题

    转:http://www.cnblogs.com/jianyungsun/archive/2011/03/19/1988855.html 这是我的vim配置文件:jeffy-vim-v2.4.tar ...

  6. 使用idea创建maven的web项目

    如果是第一次打开软件直接点击 Create New Project ,如果之前已经打开过项目了,需要点击菜单中 File → New Project … 如下图: 选择 Maven module ,输 ...

  7. iOS (catagroy)类别

    1:可以为类添加新的方法,但不能添加实例变量. 2:第一,无法向类中添加新的实例变量.类别没有位置容纳实例变量. 第二,名称冲突,即类别中的方法与现有的方法重名.当发生名称冲突时,类别具有更高的优先级 ...

  8. 【Android 界面效果19】Android中shape的使用

    Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对shape有了大体的了解,稍作总结: 先看下面的代码:         <shape>      ...

  9. 【转】使用断言NSAssert()调试程序错误

    NSAssert()只是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表达式来断定是否属于Bug,满足条件返回真值,程序继续运行,如果返回假值,则抛出异常,并切可以自定义异 ...

  10. 解决SecureCRT中文显示乱码

    操作步骤 以下两步: 远程linux机器.修改环境变量LANG.例如在~/.bash_profile里面添加 export LANG=zh_CN.UTF8 重新登录之后生效. 现在查看一下当前设置: ...