下拉列表
来源:互联网 发布:linuxmint优化 编辑:程序博客网 时间:2024/05/17 20:33
#import <UIKit/UIKit.h>
@interface DownList :UIView<UITableViewDataSource,UITableViewDelegate>
{
BOOL _isShow;
}
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSArray *dataArray;
@property(nonatomic,strong)UIButton *button;
-(instancetype)initWithFrame:(CGRect)frame andWithDataArray:(NSArray *)dataArray;
@end
#import "DownList.h"
@implementation DownList
-(instancetype)initWithFrame:(CGRect)frame andWithDataArray:(NSArray *)dataArray{
if (self = [superinitWithFrame:frame]) {
self.dataArray = dataArray;
[self createView:self.dataArray[0]];
}
return self;
}
-(void)createView:(NSString*)str{
_isShow = NO;
//创建button
self.button = [UIButtonbuttonWithType:UIButtonTypeCustom];
self.button.frame =CGRectMake(0,0, self.frame.size.width,30);
[self.buttonaddTarget:selfaction:@selector(dropDown)forControlEvents:UIControlEventAllEvents];
[self.buttonsetTitle:str forState:UIControlStateNormal];
[self.buttonsetTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
self.button.backgroundColor= [UIColoryellowColor];
[self addSubview:self.button];
//创建tableView
self.tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,30, self.frame.size.width,0) style:UITableViewStyleGrouped];
self.tableView.dataSource =self;
self.tableView.delegate =self;
self.tableView.backgroundColor = [UIColorgrayColor];
self.tableView.separatorColor = [UIColorlightGrayColor];
self.tableView.hidden =YES;
[self addSubview:self.tableView];
}
-(void)dropDown{
if (!_isShow) {
[UIViewanimateWithDuration:0.5animations:^{
CGRect sf =self.frame;
sf.size.height =200;
self.frame = sf;
CGRect frame = self.tableView.frame;
frame.size.height =150;
self.tableView.frame = frame;
self.tableView.hidden =NO;
}];
}
else{
[UIViewanimateWithDuration:0.5animations:^{
CGRect sf =self.frame;
sf.size.height =30;
self.frame = sf;
CGRect frame = self.tableView.frame;
frame.size.height =0;
self.tableView.frame = frame;
self.tableView.hidden =YES;
}];
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 50;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cell"];
}
cell.textLabel.text =self.dataArray[indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self.buttonsetTitle:self.dataArray[indexPath.row]forState:UIControlStateNormal];
CGRect frame = self.tableView.frame;
frame.size.height =0;
self.tableView.frame = frame;
self.tableView.hidden =YES;
_isShow = NO;
CGRect sf =self.frame;
sf.size.height =30;
self.frame = sf;
}
- 下拉列表
- 下拉列表
- 下拉列表
- 下拉列表
- 下拉列表
- 下拉列表
- 下拉列表
- 下拉列表
- 下拉列表
- 下拉列表
- 下拉列表
- 下拉列表
- 56民族下拉列表 民族下拉列表
- FAQ:操纵下拉列表
- 省市联动下拉列表
- 下拉列表索引
- N级联下拉列表
- 下拉列表,选左进右.
- 按钮在form外如果实现提交表单
- 判断list为空和不为空的条件
- Jquery学习之旅之动态设置css属性和获取css属性
- Web开发之四:前后端开发模式探讨
- Activiti初学者教程
- 下拉列表
- Knapsack problem(FZU2214)
- nil,Nil,NULL,NSNull区别
- 链表之交换奇偶数,实现左边为奇数,右边为偶数
- [Java学习] JavaScript实现的随机色标签云
- Hdu oj 1331 Function Run Fun(记忆化搜索)
- JavaScript在国外都那么火了,你还不来学~
- jquery datatable 多行(单行)选择(select),行获取/行删除
- android中HandlerThread的原理和用法讲解