封装遮盖&下拉菜单

在做项目的过程中有好多地方需要用到遮盖 

简单的方式就是封装一个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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值