- 浏览: 516517 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
tangyunliang:
大哥你太历害了谢谢
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
u013015029:
LZ,请问下,在// 添加消息到聊天窗口 , 这里获取Ed ...
Android基于XMPP Smack Openfire开发IM【四】初步实现两个客户端通信 -
endual:
怎么保持会话,我搞不懂啊
Android基于XMPP Smack Openfire开发IM【一】登录openfire服务器 -
donala_zq:
显示:[2013-11-30 11:50:36 - Andro ...
android-----------新浪微博 -
donala_zq:
哥,运行不了啊
android-----------新浪微博
实现的功能:1)打开ActionSheet后展示PickerView,进行选择操作。
关键词:ActionSheet PickerView
1、新建一个Sigle View Application,命名为PickerInActionSheet,工程结构如下:
[img]
[/img]
2、修改ViewController.xib,添加一个TextField控件。
3、修改ViewController.h,如下:
连接输出口textField及操作showActionSheet,如下:
[img]
[/img]
4、修改ViewController.m,如下:
5、运行效果如下:
[img]
[/img]
[img]
[/img]
关键词:ActionSheet PickerView
1、新建一个Sigle View Application,命名为PickerInActionSheet,工程结构如下:
[img]
[/img]
2、修改ViewController.xib,添加一个TextField控件。
3、修改ViewController.h,如下:
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIPickerViewDelegate,UIPickerViewDataSource> @property(retain,nonatomic)UIPickerView *picker; @property(retain,nonatomic)UIActionSheet *actionSheet; @property(retain,nonatomic)IBOutlet UITextField *textField; @property(nonatomic,retain)NSDictionary *appleDevices; @property(nonatomic,retain)NSArray *deviceCategory; @property(nonatomic,retain)NSArray *deviceName; -(IBAction)showActionSheet:(id)sender; @end
连接输出口textField及操作showActionSheet,如下:
[img]
[/img]
4、修改ViewController.m,如下:
#import "ViewController.h" #define kDeviceCategory 0 #define kDeviceName 1 @interface ViewController () @end @implementation ViewController @synthesize appleDevices; @synthesize deviceCategory; @synthesize deviceName; @synthesize picker; @synthesize actionSheet; @synthesize textField; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self initData]; } //初始化数据 -(void)initData{ textField.placeholder = @"请点击。。。"; textField.textAlignment = UITextAlignmentCenter; NSArray *array1 = [NSArray arrayWithObjects:@"iPhone",@"iPad",@"iPod",nil]; NSArray *array2 = [NSArray arrayWithObjects:@"Mac",@"iMac",@"Mac Mini",@"Mac Pro",nil]; NSDictionary *dictionary= [NSDictionary dictionaryWithObjectsAndKeys:array1,@"Mobile",array2,@"Computers",nil]; appleDevices = [[NSDictionary alloc]initWithDictionary:dictionary copyItems:YES]; NSArray *components = [self.appleDevices allKeys]; NSArray *sorted = [components sortedArrayUsingSelector:@selector(compare:)]; self.deviceCategory = sorted; NSString *selectedCategory = [self.deviceCategory objectAtIndex:0]; self.deviceName = [self.appleDevices objectForKey:selectedCategory]; } //初始化视图 -(void)showActionSheetPicker{ //在title中加入多个换行,给picker留出空间,否则picker会盖住ActionSheet的button NSString *title = @"请选择设备\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; actionSheet = [[UIActionSheet alloc] initWithTitle:title delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:nil,nil]; picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 320, 220)]; picker.delegate = self; picker.dataSource = self; picker.showsSelectionIndicator = YES; [actionSheet addSubview:picker]; [actionSheet showInView:self.view]; } -(void)dealloc{ self.deviceName = nil; self.deviceCategory = nil; self.appleDevices = nil; self.picker = nil; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } //显示actionSheet -(IBAction)showActionSheet:(id)sender{ [self showActionSheetPicker]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { //强制用竖屏模式 return UIInterfaceOrientationIsPortrait(interfaceOrientation); } #pragma mark Picker Data Source Methods - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 2; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ if(component == kDeviceCategory){ return [self.deviceCategory count]; }else{ return [self.deviceName count]; } } - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ if(component == kDeviceCategory){ return [self.deviceCategory objectAtIndex:row]; }else{ return [self.deviceName objectAtIndex:row]; } } - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{ if(component==kDeviceCategory){ return 150; }else{ return 170; } } - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{ return 35; } //显示picker中的数据 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ NSString *inputString; if(component == kDeviceCategory){ NSString *selectedCategory = [self.deviceCategory objectAtIndex:row]; NSArray *array = [self.appleDevices objectForKey:selectedCategory]; self.deviceName = array; [self.picker selectRow:0 inComponent:kDeviceName animated:YES]; [self.picker reloadComponent:kDeviceName]; inputString = selectedCategory; }else if(component == kDeviceName){ NSUInteger selectedCategoryRow = [pickerView selectedRowInComponent:kDeviceCategory]; NSString *selectedCategory = [self.deviceCategory objectAtIndex:selectedCategoryRow]; inputString = [NSString stringWithFormat:@"%@-%@",selectedCategory,[self.deviceName objectAtIndex:row]]; } //给文本框设置值 self.textField.text=inputString; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } @end
5、运行效果如下:
[img]
[/img]
[img]
[/img]
发表评论
-
新风作浪博客学习(十九)在iOS虚拟键盘上添加动态隐藏按钮
2013-06-08 09:19 816为了给用户比较良好的交付,想在键盘上添加一个按钮,实时根据键盘 ... -
新风作浪博客学习(十八)openURL的使用(iOS调用系统电话、浏览器、地图、邮件等) .
2013-06-08 09:19 932今天遇见一行代码实现打开一个网页,比起印象里的UIWebVie ... -
新风作浪博客学习(十七)UIImageView响应点击事件 .
2013-06-08 09:19 666有时候会遇到点击一张图片,然后让这张图片触发一个事件,或者是跳 ... -
新风作浪博客学习(十六)Navigation + Tab Bar 常用组合框架 .
2013-06-07 08:50 1194看到很多项目中都采用的是Navigation加Tab Bar组 ... -
新风作浪博客学习(十五)google地图定位小Demo .
2013-06-07 08:50 1058[img][/img]今天写的是一个简单功能的google地图 ... -
新风作浪博客学习(十四)怎样向iPhone模拟器中添加图片 .
2013-06-07 08:50 743在我们做项目中可能需要使用图库,模拟器是有图库的,但是如何像其 ... -
新风作浪博客学习(十三)表视图的分组分区和索引分区 .
2013-06-07 08:50 745本次实现的是表视图的分区和索引,代码和前面都差不多,主要还是代 ... -
新风作浪博客学习(十二)代码实现UITableViewCell表视图单元定制 .
2013-06-07 08:49 932通常情况下我们会希望单元格UITableViewCell显示自 ... -
新风作浪博客学习(十一)UITableViewCell的标记、移动、删除、插入 .
2013-06-06 09:15 1059这篇文章是建立在 代码实现 UITableView与UITa ... -
新风作浪博客学习(十)代码实现 UITableView与UITableViewCell .
2013-06-06 09:14 1113我们常用的表格类视图就是用 UITableView与UITab ... -
新风作浪博客学习(九)两个UIPickerView控件间的数据依赖 .
2013-06-06 09:14 1039本篇实现功能是两个选取器的关联操作,滚动第一个滚轮第二个滚 ... -
新风作浪博客学习(八)代码实现UIPickerView .
2013-06-06 09:14 1241先说一下当个组件选取器,我们创建一个数组NSAray来保存选取 ... -
新风作浪博客学习(七)代码 实现UIDatePicker控件 和 Tab Bar 视图切换 .
2013-06-06 09:15 1074感觉代码写控件都一个理,先在ViewDidLoad中创建控件对 ... -
新风作浪博客学习(六)ios 视图切换翻页效果 .
2013-06-05 11:18 1024本文写的是视图切换,涉及到的内容有 1.实现代码添加Navi ... -
新风作浪博客学习(五)代码实现UISlider 和 UISwitch .
2013-02-18 09:15 1075本次实现的UISlider和UISwi ... -
新风作浪博客学习(四)把plist里数据显示在textField上 .
2013-02-18 09:15 886在代码实现Lable 、textFie ... -
新风作浪博客学习(三)NSBundle读取图片 plist文件和txt文件
2013-02-18 09:15 1626本文想简单介绍一下NSBundle读取图片到视图上,读取pli ... -
新风作浪博客学习(二)代码实现Lable 、textField创建界面以及键盘的处理
2013-02-18 09:15 1137今天写的是用代码实现一个简单界面,代码重复率比较高,可读性不是 ... -
新风作浪博客学习(一)plist文件读写操作
2013-02-18 09:14 1301文件plist 全名Property List,属性列表文件, ... -
GCDiscreetNotificationView提示视图
2013-06-05 11:17 525先看一下效果图: [img] ...
相关推荐
自定义pickerview
安卓Android源码——PickerView.zip
自定义pickerView,实现数据的实时获取
NULL 博文链接:https://gaojian020729.iteye.com/blog/1065581
底部弹出自定义选择器,用UIScrollView实现自定义。标题,按钮均可自定义,自己可根据需求修改封装的源码,可改性很强。
仿ios-pickerView.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
PickerView.zip,Android滚动选择器控件,支持日期选择、时间选择、省市区联动选择。滚动效果流畅,支持丰富的自定义属性。
pickerView.constraintPickerViewHeight.constant = 200; pickerView.titleBackgroundColor = [UIColor whiteColor]; pickerView.separatorColor = [UIColor redColor]; [pickerView.buttonLeft setTitle:@"左边" ...
pickerview.zip,One very very user-friendly Picker library(内部提供3种常用类型的Picker:时间选择器,聚合的时间选择器和联动选择器。支持扩展自定义Picker。)
精仿iOS的PickerView控件,有时间选择和选项选择并支持一二三级联动效果——TimePickerView 时间选择器,支持年月日时分,年月日,年月,时分等格式——OptionsPickerView 选项选择器,支持一,二,三级选项选择,...
PickerView
Android-PickerView
可以简单快速的让点击TextField或者按钮弹出 单列, 多列, 多列关联数据, 城市选择器, 日期选择器, 解决注册,个人信息界面等的选择项的开发简单快速的集成各种样式的pickerView
在有的项目中使用时间选择器的时候有很多情况下不都是一样的.有的时候需要年月日,有的时候需要年月,有的时候需要年周等等这里我就同意进行了处理
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,...
IOS 开发之PickerView自定义视图的实例详解 例如选择国家,左边是名称右边是国家,不应该使用两列,而是自定义PickerView的一列,可以通过xib来实现。 注意,虽然PickerView也是一列,但是数据源方法是@required,...
预览使用首先需要在 build.gradle 文件中添加依赖:dependencies { compile 'com.airsaid.library:pickerviewlibrary:1.0.0' }添加好依赖后,重新同步工程。可根据需求使用如下选择器:城市选择: ...