ios一个可滑动列表式的弹出选择框(封装过的)
来源:互联网 发布:疯帽子雾化器做丝数据 编辑:程序博客网 时间:2024/06/05 00:25
使用方法
#import"QCPopView.h"
@interfaceRosterViewController()<QCPopViewDelegate>
@property(nonatomic,strong)QCPopView*popView;
@property(nonatomic,strong)NSString *popType;
@property(nonatomic,strong)NSString *areaIdStr;
@end
[selfpopWithArr:self.areaNameArr];
#pragma mark - QCPopView弹出
-(void)popWithArr:(NSMutableArray*)arr{
self.popView= [[QCPopViewalloc]initWithFrame:CGRectMake(0,0,[UIScreen mainScreen].bounds.size.width ,[UIScreen mainScreen].bounds.size.height)];
self.popView.QCPopViewDelegate=self;
[self.popViewshowThePopViewWithArray:arr];
}
#pragma mark -QCPopViewDelegate
-(void)getTheButtonTitleWithIndexPath:(NSIndexPath*)indexPath{
if ([self.popTypeisEqual:@"1"]) {
self.areaIdStr= [selfsetPopButtonTitleWithTag:100andIndexPath:indexPathAndNameArr:self.areaNameArrAndIdArr:self.areaIdArr];
NSLog(@"%@",self.areaIdStr);
}
}
#pragma mark - QCpPopView设置按钮内容,和隐藏
-(NSString*)setPopButtonTitleWithTag:(NSInteger)tag andIndexPath:(NSIndexPath*)indexPath AndNameArr:(NSMutableArray*)nameArr AndIdArr:(NSMutableArray*)idArr{
NSString*buttonStr = nameArr[indexPath.row];
UIButton*button = (UIButton*)[self.viewviewWithTag:tag];
[button setTitle:buttonStrforState:UIControlStateNormal];
NSString*idStr = [NSStringnew];
idStr = idArr[indexPath.row];
[self.popViewdismissThePopView];
return idStr;
}
//
// QCPopView.h
// test
//
// Created by乔超on 2017/8/8.
// Copyright © 2017年BoYaXun. All rights reserved.
//
#import<UIKit/UIKit.h>
@protocolQCPopViewDelegate <NSObject>
- (void)getTheButtonTitleWithIndexPath:(NSIndexPath*)indexPath;
@end
@interfaceQCPopView :UIView
/**
* 内容视图
*/
@property(nonatomic,strong)UIView*contentView;
/**
* 按钮高度
*/
@property(nonatomic,assign)CGFloatbuttonH;
/**
* 按钮的垂直方向的间隙
*/
@property(nonatomic,assign)CGFloatbuttonMargin;
/**
* 内容视图的位移
*/
@property(nonatomic,assign)CGFloatcontentShift;
/**
* 动画持续时间
*/
@property(nonatomic,assign)CGFloatanimationTime;
/**
* tableView的高度
*/
@property(nonatomic,assign)CGFloattableViewH;
@property(nonatomic,weak)id<QCPopViewDelegate> QCPopViewDelegate ;
/**
* 展示popView
*
* @param array button的title数组
*/
- (void)showThePopViewWithArray:(NSMutableArray*)array;
/**
* 移除popView
*/
- (void)dismissThePopView;
@end
//
// QCPopView.m
// test
//
// Created by乔超on 2017/8/8.
// Copyright © 2017年BoYaXun. All rights reserved.
//
#import"QCPopView.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define LineColor [UIColor colorWithRed:242.0/255.0green:242.0/255.0blue:242.0/255.0alpha:1.0]
@interfaceButtonTableViewCell :UITableViewCell
@property(nonatomic,strong)UILabel*label;
@end
@implementationButtonTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
self= [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];
if(self) {
self.label= [[UILabelalloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH-40,SCREEN_HEIGHT* (40.0/736.0))];
self.label.textAlignment=NSTextAlignmentCenter;
self.label.font= [UIFontsystemFontOfSize:14];
[selfaddSubview:self.label];
UIView*view = [UIViewnew];
[selfaddSubview:view];
view.backgroundColor=LineColor;
view.frame=CGRectMake(0,SCREEN_HEIGHT* (40.0/736.0),SCREEN_WIDTH-40,1);
}
returnself;
}
@end
@interfaceQCPopView()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView*tableView;
@property(nonatomic,strong)NSArray*dataSource;
@property(nonatomic,strong)UIView*bgView;
@end
@implementationQCPopView
- (instancetype)initWithFrame:(CGRect)frame{
if(self= [superinitWithFrame:frame]) {
self.frame= frame;
//初始化各种起始属性
[selfinitAttribute];
[selfinitTabelView];
}
returnself;
}
- (void)initTabelView{
self.tableView= [[UITableViewalloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH-40,self.contentShift)style:UITableViewStylePlain];
self.tableView.layer.cornerRadius=10;
self.tableView.delegate=self;
self.tableView.dataSource=self;
self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
[self.tableViewregisterClass:[ButtonTableViewCellclass]forCellReuseIdentifier:@"cell1"];
[self.contentViewaddSubview:self.tableView];
}
/**
* 初始化起始属性
*/
- (void)initAttribute{
self.buttonH=SCREEN_HEIGHT * (40.0/736.0)+1;
self.buttonMargin=10;
self.contentShift=SCREEN_HEIGHT * (250.0/736.0);
self.animationTime=0.8;
self.backgroundColor= [UIColorcolorWithWhite:0.614alpha:0.700];
[selfinitSubViews];
}
/**
* 初始化子控件
*/
- (void)initSubViews{
self.contentView= [[UIViewalloc]init];
self.contentView.backgroundColor= [UIColorwhiteColor];
self.contentView.layer.cornerRadius=10;
self.contentView.frame=CGRectMake(20,150,SCREEN_WIDTH-40,self.contentShift);
[selfaddSubview:self.contentView];
}
/**
* 展示pop视图
*
* @param array需要显示button的title数组
*/
- (void)showThePopViewWithArray:(NSMutableArray*)array{
UIWindow*window = [[UIApplicationsharedApplication].windowsfirstObject];
[windowaddSubview:self];
self.dataSource= array;
}
- (void)dismissThePopView{
[selfremoveFromSuperview];
}
- (void)touchesBegan:(NSSet<UITouch*> *)touches withEvent:(UIEvent*)event{
[selfdismissThePopView];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
returnself.dataSource.count;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
ButtonTableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"forIndexPath:indexPath];
NSString* buttonStr = self.dataSource[indexPath.row];
cell.label.text= buttonStr;
returncell;
}
#pragma mark - UITableViewDelagate
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
returnself.buttonH;
}
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
if([self.QCPopViewDelegaterespondsToSelector:@selector(getTheButtonTitleWithIndexPath:)]) {
[self.QCPopViewDelegategetTheButtonTitleWithIndexPath:indexPath];
}
}
@end
阅读全文
0 0
- ios一个可滑动列表式的弹出选择框(封装过的)
- iOS星级选择,可滑动的,可点击
- 仿微信的列表滑动删除(一) 可滑动控件
- 弹出列表框,响应选择的数据
- 注册一个 长按listView的item弹出选择列表
- 列表选择的简单封装
- iOS弹出框封装好的方法
- JavaScript 弹出一个可移动的框
- Android 弹出可供选择的弹框
- ios开发--地址选择封装的一个demo
- 一个可以选择日期的弹出框(附在EditText)
- jquery封装了一个简洁轻巧的可拖动可自定义样式的纯div+css带遮罩层的仿模态弹出框
- textview在内容过多时可上下滑动的实现
- 一个不完善的可自定义弹出窗体的下拉框
- 一个简单的可滑动ViewpagerIndicator
- 可滑动弹出菜单的自定义Layout,基于ViewGroup
- 类似智联招聘选择职位的弹出框效果,可做选择城市等信息
- iOS---弹出提示对话框的封装
- 自助式商业智能可视化工具,移动BI不是梦
- 获得html表单中radio name相同的数组的值 并判断每个选项不能为空
- github上面MD文件书写格式说明
- 5分钟了解Mockito
- 大众点评数据分析报告
- ios一个可滑动列表式的弹出选择框(封装过的)
- 关于子类和父类之间的方法调用关系
- NOIP2017模拟day1 T3 string splay 置换
- Mybatis缓存
- Linux下Mysql安装及问题
- 网狐荣耀版手机端生成时出现MakeMD5List.exe 应用程序错误的解决办法
- 光学字符识别技术:让电脑像人一样阅读
- Android 正则表达式大全(通用版)
- 从尾到头打印链表 (剑指Offer 第 3 题)