ios学习:UIToolBar的单独使用
toolbar除了可以和navigationController一起用之外,也可以独立用到view里
1 // 2 // TWFXToolBarViewController.m 3 // DemoToolBar 4 // 5 // Created by Lion User on 13-1-19. 6 // Copyright (c) 2013年 Lion User. All rights reserved. 7 // 8 9 #import "TWFXToolBarViewController.h" 10 11 @interface TWFXToolBarViewController () 12 13 @end 14 15 @implementation TWFXToolBarViewController 16 17 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 18 { 19 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 20 if (self) { 21 // Custom initialization 22 23 //创建toolbar 24 UIToolbar *toolBar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 420.0f, 320.0f, 40.0f) ] autorelease]; 25 26 //创建barbuttonitem 27 UIBarButtonItem *item1 = [[[UIBarButtonItem alloc] initWithTitle:@"收藏" style:UIBarButtonItemStyleBordered target:self action:@selector(test:)] autorelease]; 28 29 //创建barbuttonitem 30 UIBarButtonItem *item2 = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:nil] autorelease]; 31 32 //创建一个segmentController 33 UISegmentedControl *seg = [[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"牛扒", @"排骨", nil] ] autorelease]; 34 35 //设置style 36 [seg setSegmentedControlStyle:UISegmentedControlSegmentCenter]; 37 38 39 [seg addTarget:self action:@selector(segmentControllerItem:) forControlEvents:UIControlEventValueChanged]; 40 41 //创建一个内容是view的uibarbuttonitem 42 UIBarButtonItem *itemSeg = [[[UIBarButtonItem alloc] initWithCustomView:seg] autorelease]; 43 44 //创建barbuttonitem,样式是flexible,这个种barbuttonitem用于两个barbuttonitem之间 45 //调整两个item之间的距离.flexible表示距离是动态的,fixed表示是固定的 46 UIBarButtonItem *flexible = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease]; 47 48 //把item添加到toolbar里 49 [toolBar setItems:[NSArray arrayWithObjects:item1,flexible,itemSeg,flexible,item2, nil] animated:YES]; 50 51 //把toolbar添加到view上 52 [self.view addSubview:toolBar]; 53 54 } 55 return self; 56 } 57 58 - (void)viewDidLoad 59 { 60 [super viewDidLoad]; 61 // Do any additional setup after loading the view from its nib. 62 } 63 64 -(void)test:(id)sender 65 { 66 UIBarButtonItem *item = (UIBarButtonItem *) sender; 67 NSString *title = [NSString stringWithFormat:@"%@ 被选中了",item.title]; 68 69 UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Attention" message:title delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil] autorelease]; 70 71 [alertView show]; 72 } 73 74 75 -(void)segmentControllerItem:(id)sender 76 { 77 UISegmentedControl *seg = (UISegmentedControl *) sender; 78 NSInteger index = seg.selectedSegmentIndex; 79 NSString *message; 80 if (index == 0) { 81 message = @"你选了牛扒"; 82 } 83 else 84 { 85 message = @"你选了排骨"; 86 } 87 88 UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:@"Attenton" message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease]; 89 90 [alertView show]; 91 } 92 93 - (void)didReceiveMemoryWarning 94 { 95 [super didReceiveMemoryWarning]; 96 // Dispose of any resources that can be recreated. 97 } 98 99 - (IBAction)goBack:(UIButton *)sender { 100 101 [self dismissViewControllerAnimated:YES completion:nil]; 102 } 103 @end
ios学习:UIToolBar的单独使用相关推荐
- ios学习--iphone开发笔记和技巧总结(原址持续更新)
ios学习--iphone开发笔记和技巧总结(原址持续更新) 分类: ios Object-C2012-04-18 10:16 2716人阅读 评论(1) 收藏 举报 uiviewiphonelist ...
- iOS学习路线图--UIKIt概述
1.先分享一张iOS学习路线图吧,网上找的,感觉不错 2.再来一张UIkit类框架图,也是网上找的 3.UIkit各类概述 1.UIAcceleration: 被叫做加速事件的一个UIAccelera ...
- 【原】iOS学习之事件处理的原理
在iOS学习23之事件处理中,小编详细的介绍了事件处理,在这里小编叙述一下它的相关原理 1.UITouch对象 在触摸事件的处理方法中都会有一个存放着UITouch对象的集合,这个参数有什么用呢? ( ...
- iOS学习——核心动画之Layer基础
iOS学习--核心动画之Layer基础 1.CALayer是什么? CALayer我们又称它叫做层.在每个UIView内部都有一个layer这样一个属性,UIView之所以能够显示,就是因为它里面有这 ...
- OpenCV for Ios 学习笔记(4)-标记检测1
本文原始地址:OpenCV for Ios 学习笔记(4)-标记检测1 简单的标记经常是以白色块和黑色块构成的规则图形.因为我们预先知道这些因素,所以我们可以很容易检测标记. 如图: 首先,我们需要找 ...
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法...
IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法 Author:hmjiangqq Email:jiangqqlmj@163.com ...
- IOS学习笔记(四)之UITextField和UITextView控件学习
IOS学习笔记(四)之UITextField和UITextView控件学习(博客地址:http://blog.csdn.net/developer_jiangqq) Author:hmjiangqq ...
- iOS学习资源(一)
用了印象笔记也很久了,这里就把自己整理的一些学习资源分享出来.需要共享印象笔记的小伙伴可以联系: shavekevin@gmail.com 我会把自己的工作笔记共享给大家,和大家一起学习,一起进步. ...
- iOS学习之iOS沙盒(sandbox)机制和文件操作(二)
接上篇 iOS学习之iOS沙盒(sandbox)机制和文件操作(一) 我们看看如何获取应用程序沙盒目录.包括真机的沙盒的目录. 1.获取程序的Home目录 [cpp] view plaincopy N ...
- IOS学习之蓝牙4.0
转载请注明出处 作者:小马 IOS学习也一段时间了,该上点干货了.前段时间研究了一下IOS蓝牙通讯相关的东西,把研究的一个成果给大家分享一下. 一 项目背景 简单介绍一下做的东西,设备是一个金融刷卡器 ...
最新文章
- 从Excel中导入数据时,提示“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”的解决办法...
- phpstorm配置Xdebug
- 全网最通透的“闭包”认知 · 跨越语言
- 《ASP.NET Core 微服务实战》-- 读书笔记(第9章)
- C++经典书籍和相关内容
- olap 多维分析_OLAP(在线分析处理)| OLAP多维数据集和操作
- log4j日志级别以及配置
- 实战案例:探索星巴克的世界分布
- java继承案例分析,Java day5【第十四章】继承案例分析
- 运放输入偏置电流方向_运算放大器的输入偏置电流
- 电脑出现missing operating system解决办法
- JSON与csv哪一个更自描述_徒步进藏和骑行进藏旅行,哪一个更辛苦
- ROS下使用C++读取txt文本数据并使用
- 轻松使用Nginx搭建web服务器
- Halcon如何创建或生成空白的,全黑或全白的8位图和24位图
- mysql常用日期的写法
- floodFill详解
- C++ swap用法
- 使用Python将多个单独的Excel文件整合到一个Excel文件的不同工作表里
- 本版1年以内的所有 面经题目