ios学习--iphone 实现下拉菜单
#import
@interface DropDown1 : UIView <</span>UITableViewDelegate,UITableViewDataSource> {
UITableView *tv;//下拉列表
NSArray *tableArray;//下拉列表数据
UITextField *textField;//文本输入框
BOOL showList;//是否弹出下拉列表
CGFloat tabheight;//table下拉列表的高度
CGFloat frameHeight;//frame的高度
}
@property (nonatomic,retain) UITableView *tv;
@property (nonatomic,retain) NSArray *tableArray;
@property (nonatomic,retain) UITextField *textField;
@end
#import "DropDown1.h"
@implementation DropDown1
@synthesize tv,tableArray,textField;
- (void)dealloc
{
[tv release];
[tableArray release];
[textField release];
[super dealloc];
}
-(id)initWithFrame:(CGRect)frame
{
if (frame.size.height<<span style="color: #2934d5">200) {
frameHeight = 200;
}else{
frameHeight = frame.size.height;
}
tabheight = frameHeight-30;
frame.size.height = 30.0f;
self=[super initWithFrame:frame];
if(self){
showList = NO; //默认不显示下拉框
tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 30, frame.size.width, 0)];
tv.delegate = self;
tv.dataSource = self;
tv.backgroundColor = [UIColor grayColor];
tv.separatorColor = [UIColor lightGrayColor];
tv.hidden = YES;
[self addSubview:tv];
textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 30)];
textField.borderStyle=UITextBorderStyleRoundedRect;//设置文本框的边框风格
[textField addTarget:self action:@selector(dropdown) forControlEvents:UIControlEventAllTouchEvents];
[self addSubview:textField];
}
return self;
}
-(void)dropdown{
[textField resignFirstResponder];
if (showList) {//如果下拉框已显示,什么都不做
return;
}else {//如果下拉框尚未显示,则进行显示
CGRect sf = self.frame;
sf.size.height = frameHeight;
//把dropdownList放到前面,防止下拉框被别的控件遮住
[self.superview bringSubviewToFront:self];
tv.hidden = NO;
showList = YES;//显示下拉框
CGRect frame = tv.frame;
frame.size.height = 0;
tv.frame = frame;
frame.size.height = tabheight;
[UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
self.frame = sf;
tv.frame = frame;
[UIView commitAnimations];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [tableArray objectAtIndex:[indexPath row]];
cell.textLabel.font = [UIFont systemFontOfSize:16.0f];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 35;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
textField.text = [tableArray objectAtIndex:[indexPath row]];
showList = NO;
tv.hidden = YES;
CGRect sf = self.frame;
sf.size.height = 30;
self.frame = sf;
CGRect frame = tv.frame;
frame.size.height = 0;
tv.frame = frame;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
DropDown1 *dd1 = [[DropDown1 alloc] initWithFrame:CGRectMake(10, 10, 140, 100)];
dd1.textField.placeholder = @"请输入联系方式";
NSArray* arr=[[NSArray alloc]initWithObjects:@"电话",@"email",@"手机",@"aaa",@"bbb",@"ccc",nil];
dd1.tableArray = arr;
[arr release];
[self.view addSubview:dd1];
[dd1 release];
ios学习--iphone 实现下拉菜单的更多相关文章
- iphone动态下拉菜单
介绍:实现带动画效果的下拉菜单.用户按下菜单按钮,出现下拉按钮,用户松开菜单按钮,下拉按钮收回. 测试环境:Xcode 4.3, iOS 5.0. 效果图: jQuery特效:http://www.h ...
- BootStrap学习(2)_下拉菜单&按钮组
一.下拉菜单 1.基本下拉菜单 如需使用下列菜单,只需要在class .dropdown 内加上下拉菜单即可.下面的实例演示了基本的下拉菜单: <!DOCTYPE html> <ht ...
- Bootstrap3.0学习第十轮(下拉菜单、按钮组、按钮式下拉菜单)
详情请查看http://aehyok.com/Blog/Detail/16.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...
- Bootstrap 学习笔记8 下拉菜单滚动监听
代码部分: <nav class="navbar navbar-default"> <a href="#" class="navba ...
- 如何在webapp中做出原生的ios下拉菜单效果
github:https://github.com/zhoushengmufc/iosselect webapp模仿ios下拉菜单 html下拉菜单select在安卓和IOS下表现不一样,iossel ...
- IOS 下拉菜单
由于之前曾经用到过下拉菜单,所以现在花一些时间回过头来细细整理了一下,逐步完善这个下拉菜单,并提供一些比较基本的功能,以便日后如果有需要的话可以进行复用,并提供给需要的人参考.下拉菜单同样分为数据源和 ...
- Android:有关下拉菜单导航的学习(供自己参考)
Android:有关==下拉菜单导航==的学习 因为先前的学习都没想着记录自己的学习历程,所以该博客才那么迟才开始写. 内容: ==下拉菜单导航== 学习网站:android Spinner控件详解 ...
- IOS第二天-新浪微博 - 添加搜索框,弹出下拉菜单 ,代理的使用 ,HWTabBar.h(自定义TabBar)
********HWDiscoverViewController.m(发现) - (void)viewDidLoad { [super viewDidLoad]; // 创建搜索框对象 HWSearc ...
- iOS 下拉菜单 FFDropDownMenu自定义下拉菜单样式实战-b
Demo地址:https://github.com/chenfanfang/CollectionsOfExampleFFDropDownMenu框架地址:https://github.com/chen ...
随机推荐
- Django 数据表更改
Django 数据表更改 « Django 开发内容管理系统(第四天) Django 后台 » 我们设计数据库的时候,早期设计完后,后期会发现不完善,要对数据表进行更改,这时候就要用到本节的知识. D ...
- lsof 查看文件被哪个进程占用
lsof 是什么意思? 答: list open files 查看某个文件被哪些进程在读写 lsof 文件名 查看某个进程打开了哪些文件lsof –c 进程名lsof –p 进程号 lsof用法小全 ...
- 终端下将 man 命令的结果输出到文件保存
终端下将 man 命令的结果输出到文件保存 在linux或mac下,当我们使用man命令查看某一个命令的详细帮助说明信息时: 可能终端的显示效果不是那么方便: 那么我们可以将man命令的结果输出到tx ...
- 运行Keras版本的Faster R-CNN(1)
Keras版本的Faster R-CNN源码下载地址:https://github.com/yhenon/keras-frcnn下载以后,用PyCharm打开(前提是已经安装了Tensorflow-g ...
- np.memmap读取大文件
Numpy中的ndarray是一种新形式的Python内建类型.因此,它可以在需要时被继承.ndarray形成了许多有用类的基础. np.memmap就是其中一种,它是内存映射文件.本质上就是使用C语 ...
- redis详解(三)-- 面试题(转载)
1. 使用redis有哪些好处? (1) 速度快,因为数据存在内存中,类似于HashMap,HashMap的优势就是查找和操作的时间复杂度都是O(1) (2) 支持丰富数据类型,支持string,li ...
- server后台TCP连接存活问题
公司的server后台部署在某一个地方,接入的是用户的APP,而该地方的网络信号较差,导致了server后台在执行一段时间后用户无法接入,那边的同事反馈使用netstat查看系统.存在较多的TCP连接 ...
- SNF软件开发机器人-子系统-功能-【列表】自由排序-如何配置?
[列表]自由排序 1.效果展示: 2.使用说明: 打开显示页面,点击开发者选项的简单配置按钮.在功能表信息中选择自由排序复选框后保存.
- 移动开发常用meta设置
<!-- 视图窗口,移动端特属的标签. --> <meta name="viewport" content="width=device-width,in ...
- 【Wildfly】从默认的自动重启修改为手动重启
最近在使用Wildfly作为Web服务器,用的是10.0.0版本.默认情况下,Wildfly的部署方式是通过将项目放到%WILDFLY_HOME%\standalone\deployments下的,然 ...