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 ...
随机推荐
- C# System.IO.FileMode
字段 Append 6 若存在文件,则打开该文件并查找到文件尾,或者创建一个新文件. 这需要 Append 权限. FileMode.Append 只能与 FileAccess.Write 一起使用. ...
- 在windows命令行批量ping局域网内IP
参考了博客园Alfred Zhao的文章<Windows平台ping测试局域网所有在用IP> 在cmd命令行运行如下命令即可: ,,) -w .%i | find "回复&quo ...
- Linux下清理内存和Cache方法见下文:
暂时目前的环境处理方法比较简单: 在root用户下添加计划任务: */10 * * * * sync;echo 3 > /proc/sys/vm/drop_caches; 每十分钟执行一次,先将 ...
- elasticsearch外网访问设置
默认情况下安装elasticsearch之后是无法进行外网访问的,可以通过设置来完成这一目的 1.更改配置文件 [***@elk01 ~]$ vim elk/config/elasticsearch. ...
- IDEA使用笔记(十)——设置Java方法注释
如果你看到了,这篇博文,那么你是幸运的!你问什么?你百度百度同类型的网文就明白了! 一:先看效果 二:我的实验过程(肯定还有别的方式) 1:新建 Template Group,详细操作步骤见下图 ...
- macOS 下 PHPStorm + Xdebug 调试 Docker 环境中的代码
0x00 描述 宿主机是 mac mini,构建的项目在 docker 中,所以需要在 PHPStorm 上配置 Xdebug 进行远程代码调试. 0x01 环境 宿主机:macOS High Sie ...
- SQLServer截取字符串常用函数
SQL Server中一共提供了三个字符串截取函数:LEFT().RIGHT().SUBSTRING(). 一.LEFT()函数 函数说明如下: 语法:LEFT(character,integer). ...
- [Java]判断Integer值相等最好不用==最好使用equals
测试代码 Integer c = ; Integer d = ; Integer e = ; Integer f = ; System.out.println(c == d); System.out. ...
- (原)关于udp的socket发送数据耗时的问题探讨
转载请注明出处:http://www.cnblogs.com/lihaiping/p/6811791.html 本学习笔记,仅用于问题探讨,如有不同,可以讨论. 最近在看流媒体分发服务器的相关代码,其 ...
- 如何查看SQL SERVER数据库当前连接数
SELECT * FROM[Master].[dbo].[SYSPROCESSES] WHERE [DBID] IN ( SELECT [DBID]FROM [Master].[dbo].[SYSDA ...