//
// 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. HTML5 修改浏览器url而不刷新页面

    嘛,起因是黑子大叔在微博上的一条@信息,找起了这个的实现,看了一圈google的中文信息内似乎还没有怎么提到这个的内容,就发表上来. 详细效果就是类似于用Firefox4+/Chrome 5+/Saf ...

  2. swift app中展示折线图, 饼状图, 柱状图等数据图表

    github 下载Charts-master SDK,该SDK有多种可自定义的图表样式 lineChart 正弦余弦线图 LineChart (cubic lines) LineChart (grad ...

  3. 深入了解android平台的jni---图像灰度化处理

    一.涉及到的jni编程知识 Java基本类型的数组,在JNI中都是jArray的类型格式.具体类型如下: typedef jarray jbooleanArray; typedef jarray jb ...

  4. 0c-39-ARC下单对象内存管理

    1.ARC工作原理详述 ARC是Objective-C编译器的特性,而不是运行时特性或者垃圾回收机制,ARC所做的只不过是在代码编译时为你自动在合适的位置插入release或autorelease A ...

  5. Spring MVC @RequestMapping Annotation Example with Controller, Methods, Headers, Params, @RequestParam, @PathVariable--转载

    原文地址: @RequestMapping is one of the most widely used Spring MVC annotation.org.springframework.web.b ...

  6. 解决faststone capture在台式机上录制屏幕视频没有声音的问题

    点击屏幕录像机: 在弹出的屏幕录像机窗口中选择录制音频,然后点击选项按钮: 在弹出的选项按钮中选择视频选项,将所有的多选框都选中,注:最后一个选项录制windows XP的工具提示最好也选上,我发现如 ...

  7. 二手奢侈品电商Vestiaire Collective融资2000万美元

    巴黎奢侈品电商Vestiaire Collective获得了2000万美元的C轮融资,投资方包括知名出版集团Condé Nast.Idinvest.Balderton和Ventech,其中Condé ...

  8. 批量更新memcached缓存

    假如系统里有3类数据company,user,product 利用维护版本号version的方式达到批量更新缓存的效果 memcache.Add("company",cversio ...

  9. 控制反转(IoC)

          大量使用工厂模式引起的问题:       Client 对象需要使用 Service1 的 execute( ) 方法完成特定功能,而 Service1 的实现 Service1Impe类 ...

  10. 剑指Offer35 两个链表第一个公共结点

    /************************************************************************* > File Name: 35_FirstC ...