在做项目的过程中有好多地方需要用到遮盖
简单的方式就是封装一个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