最近做了一个需求是点击按钮弹出下拉选项框,在这里记录一下封装过程,使用简单,只需
ws.managerObject = [[XFKFSUtilitiPopSelectItemsView alloc] initWithSelectArr:ws.selectTitleArray];
ws.managerObject.delegate = ws;
[ws.managerObject presenFromeSelectView:sender];
然后实现
- (void)selectWithIndext:(NSInteger)index{
//do something
}
- (void)curentViewDidDismiss{
self.managerObject = nil;
}
效果图
在这里把头文件展示出来
@protocol CWCUtilitiPopSelectItemsViewSelectDelegate <NSObject>
@optional
/**
选择item的回调
@param index 标记位
*/
- (void)selectWithIndext:(NSInteger)index;
/**
视图移除后的回调
*/
- (void)curentViewDidDismiss;
@end
typedef NS_ENUM(NSInteger, CWCPopType)
{
CWCType_Left,
CWCType_Right,
};
@interface CWCUtilitiPopSelectItemsView : NSObject
/**
初始化
@param selectArr 可选数组
@return 实例
*/
- (instancetype)initWithSelectArr:(NSMutableArray *)selectArr;
/**
显示视图
@param selectView 目标视图
*/
- (void)presenFromeSelectView:(UIView *)selectView;
/**
移除视图
*/
- (void)dismissAction;
/**
* 代理
*/
@property (nonatomic, weak) id <CWCUtilitiPopSelectItemsViewSelectDelegate> delegate;
/**
* 视图底图
*/
@property (nonatomic, strong) UIView *managerView;
/**
* 弹出原始位置
*/
@property (nonatomic, assign) CWCPopType popType;
效果