ios之UIToolBar
toolbar除了可以和navigationController一起用之外,也可以独立用到view里。工具栏UIToolbar – 一般显示在底部,用于提供一组选项,让用户执行一些功能,而并非用于在完全不同的UI界面之间切换;在不同 UI 界面切换,是选项卡 Tab Bar负责的。

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中 UIToolBar 技术分享
UIToolBar存在于UINavigationController导航栏控制器中,而且默认被隐藏.当设置UIToolBar显示,或者存在UITabBarController且tabbar被隐藏的时候 ...
- iOS - UIToolbar
前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIToolbar : UIView <UIBarPositioning& ...
- ios 开发UI篇— UIToolbar
前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIToolbar : UIView <UIBarPositioning& ...
- iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结
原文: http://blog.csdn.net/songrotek/article/details/8692866?utm_source=tuicool 对于UIToolbar,UINavigat ...
- iOS开发——UI篇Swift篇&UIToolbar
UIToolbar class UIToolBarUISearchBar: UIViewController,UISearchBarDelegate { var titleString:String! ...
- [iOS基础控件 - 6.10.3] DatePicker & UIToolBar
A.需求 1. 学习DatePicker的基本配置 2.使用TextField召唤指定类型的输入键盘View,这里使用DatePicker 3.给输入键盘上方加上一个UIToolBar,实现如关闭键盘 ...
- 【iOS发展-70】点菜系统案例:使用文本框inputView和inputAccessoryView串联UIPickerView、UIDatePicker和UIToolBar
(1)效果 (2)先在storyboard中设计界面,然后源码(直接在ViewController中码) #import "ViewController.h" @interface ...
- 【IOS 开发】基本 UI 控件详解 (UIDatePicker | UIPickerView | UIStepper | UIWebView | UIToolBar )
转载注明出处 : http://blog.csdn.net/shulianghan/article/details/50348982 一. 日期选择器 (UIDatePicker) UIDatePic ...
- iOS:UIToolBar控件的使用
UIToolBar控件:是经常使用的一个工具条控件,虽然在上面可以添加子控件,但是toolbar中只能添加UIBarButtonItem类型的子控件,其他子控件会被包装成这种类型的,例如UIButto ...
随机推荐
- 三轴陀螺仪与加速度计如何辅助 iPhone 定位的
在所有之前解释一下陀螺仪 根据Wiki的定义:「陀螺仪是用于测量角度或维持方向的设备,基于角动量守恒原理.」 这句话的要点是测量角度或维持方向,这是 iPhone 4 为何搭载此类设备的原因.机械陀螺 ...
- Inside Geometry Instancing(上)
Inside Geometry Instancing(上) http://blog.csdn.net/soilwork/article/details/598335 翻译:claymanclayman ...
- CF364D Ghd(随机化)
另一个集合\(s\)的\(ghd\)为\(max\{gcd(s')||s'|>=0.5|s|\}\) 给定序列\(a\),求\(ghd\) 随机化算法.因为\(|s'|\geq 0.5|S|\) ...
- IT兄弟连 JavaWeb教程 JSP定义
JSP页面是指扩展名为.jsp的文件,在一个JSP页面中,可以包括指令标识.HTML代码.JavaScript代码.嵌入的Java代码.注释和JSP动作标识等内容.但这些内容并不是一个JSP页面所必须 ...
- java基础第一篇
1.JDK:Java Development kit 能对Java程序编译,运行 包含JRE JRE:Java Runtime Environment 能对Java程序运行 包含JVM和一些核心类库 ...
- oracle tps
http://blog.csdn.net/nilxin/article/details/5812480 sample 1: 定义 TPS:Transactions Per Second(每秒传输的事物 ...
- web基础笔记
浏览器渲染页面的过程 浏览器渲染页面前需要先构建 DOM 和 CSSOM 树.因此,我们需要确保尽快将 HTML 和 CSS 都提供给浏览器. 参考:https://developers.google ...
- 17999 Light-bot 模拟 + kmp求循环节
http://acm.scau.edu.cn:8000/uoj/mainMenu.html 17999 Light-bot 时间限制:1000MS 内存限制:65535K 提交次数:0 通过次数:0 ...
- Linux 增加虚拟内存
1. 用 df -h 命令找一个比较大的磁盘空间 2.建立swap文件 大小为2G count= 3.启用虚拟内存 1. 将swap文件设置为swap分区文件 mkswap swapfile #(由于 ...
- 顾问Advisor Aspectj注解
顾问Advisor 通知 advice PointcutAdvisor 一个接口 是顾问的一种. . 任意单个字符 + 重复1到多次 * 重复0到多次 NameMetchMethodPointc ...