封装遮盖&下拉菜单
2015-12-29 17:33
351 查看
在做项目的过程中有好多地方需要用到遮盖
简单的方式就是封装一个view 放在上面 这里遮盖上有个下拉菜单
简单的方式就是封装一个view 放在上面 这里遮盖上有个下拉菜单
// // EFPopView.h // downMessage // #import <UIKit/UIKit.h> @class EFPopView; @protocol efPopViewDelegate <NSObject> - (void)changeCatoryMessage:(EFPopView *)popView andIndex:(NSIndexPath *)index andMessage:(NSString *)catoryMessage; @end @interface EFPopView : UIView @property (nonatomic, assign)id<efPopViewDelegate>delegate; + (instancetype)efPopView; @end
// // EFPopView.m // downMessage // #import "EFPopView.h" #import "EFCategoryMessageTableViewCell.h" static CGFloat const kTableViewRowHeigh = 40; static NSString *EFCategoryMessageTableViewCellID = @"EFCategoryMessageTableViewCell"; @interface EFPopView() <UITableViewDelegate, UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) NSArray *dataArray; @end @implementation EFPopView #pragma mark - 懒加载 - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] init]; _tableView.delegate = self; _tableView.dataSource = self; [self addSubview:_tableView]; } return _tableView; } - (NSArray *)dataArray { if (!_dataArray) { _dataArray = [NSArray array]; _dataArray = @[@"上门服务", @"燃气谱表", @"智能蓝牙卡", @"CNG加气", @"水", @"电", @"暖"]; } return _dataArray; } - (instancetype)init { if (self = [super init]) { [self tableView]; [self dataArray]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; _tableView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/2, 0, [UIScreen mainScreen].bounds.size.width/2, 280); // 注册 [self.tableView registerNib:[UINib nibWithNibName:EFCategoryMessageTableViewCellID bundle:[NSBundle mainBundle]] forCellReuseIdentifier:EFCategoryMessageTableViewCellID]; self.tableView.tableFooterView = [[UIView alloc] init]; } + (instancetype)efPopView { return [[self alloc] init]; } #pragma mark - DataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return _dataArray.count; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { EFCategoryMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EFCategoryMessageTableViewCellID forIndexPath:indexPath]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.messageLabel.text = _dataArray[indexPath.row]; return cell; #if 0 static NSString *cellName = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellName]; } cell.textLabel.text = @"test"; return cell; #endif } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (self.delegate&&[self.delegate respondsToSelector:@selector(changeCatoryMessage:andIndex:andMessage:)]) { [_delegate changeCatoryMessage:self andIndex:indexPath andMessage:_dataArray[indexPath.row] ]; }} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return kTableViewRowHeigh; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end
相关文章推荐
- dos 批处理for循环
- 别样JAVA学习(五)继承上(1.0)Object类equals()
- 教你一眼认出英语单词的意思
- 手势图的设计原理(1)建立、开始、移动、结束、点击、长按
- 深浅拷贝的应用-copy、mutableCopy
- [.NET源码] C#制作的一套在线更新软件系统
- AngularJs基础——过滤器
- MVC框架详解--Servlet+JSP+JavaBean模式(MVC)开发复杂的web应用
- 万能js实现翻页,动态生成内容自动翻页,兼容各种浏览器(已测试)----神器版!
- R语言实战
- 如何确定Ubuntu下是否对某个CVE打了补丁
- 思杰成为ADC领域在Container容器中提供其产品的第一家主要厂商
- 正则表达式:匹配任意字符
- 关于struts页面数字的格式化
- 获取WebView加载HTML时网页中的内容
- 【莫比乌斯反演】关于Mobius反演与gcd的一些关系与问题简化(bzoj 2301 Problem b&amp;&amp;bzoj 2820 YY的GCD&amp;&amp;BZOJ 3529 数表)
- 文件夹树
- Git使用教程
- Python实现抓取糗事百科的段子
- linux2--ssh secure shell client