控件 WMZDropDownMenu
為什么寫這個控件?
主流的篩選菜單很多都是固定樣式的,很多時候要使用都要去改變源碼才能變成我們想要的樣子,于是我就想寫一個控件,只需要調(diào)用代理就能實(shí)現(xiàn)幾乎所有功能的篩選功能
實(shí)現(xiàn)功能
- 組合自定義功能
- 支持自定義多選|單選|復(fù)選
- 支持自定義彈出的動畫 (目前已實(shí)現(xiàn)向下,向左全屏,向右全屏,拼多多對話框彈出,boss直聘全屏彈出)
- 支持自定義tableView/collectionView頭尾視圖
- 支持自定義全局頭尾視圖
- 支持自定義collectionCell/tableViewCell視圖
- 支持自定義標(biāo)題
- 支持自定義點(diǎn)擊回收視圖
- 支持自定義回收列表
- 支持任意級的聯(lián)動(由于數(shù)據(jù)比較龐雜,暫時自動適配不了無限級的聯(lián)動,所以需要你調(diào)用一個方法更新數(shù)據(jù)傳給我,詳情看Demo)
- 支持嵌套使用,即兩個篩選菜單可以連著使用
- 支持放在放在任意視圖上,tableviewHeadView毫無疑問支持且無須寫其他代碼只要放上去即可
- 支持控制器消失自動關(guān)閉視圖,無須再控制器消失方法里手動關(guān)閉
- 鏈?zhǔn)綄?shí)現(xiàn)所有配置的自定義修改
(總之,你想要的基本都有,不想要的也有)
目前已經(jīng)用這控件實(shí)現(xiàn)的效果圖
????????無須改變源碼 只需要調(diào)用我的代理組合功能即可????????
| app篩選菜單 | 圖片 |
|---|---|
| 仿閑魚篩選菜單 | ![]() xianyu.gif
|
| 仿美團(tuán)篩選菜單 | ![]() meituan.gif
|
| 餓了么篩選菜單 | ![]() eleme.gif
|
| 京東篩選菜單 | ![]() Jingdong.gif
|
| 拼多多篩選菜單 | ![]() pinduoduo.gif
|
| 簡書篩選菜單 | ![]() jianshu.gif
|
| 趕集網(wǎng)篩選菜單 | ![]() ganjiwang.gif
|
| 美團(tuán)外賣篩選菜單 | ![]() meituanwaimai.gif
|
| Boss直聘篩選菜單 | ![]() Boss.gif
|
| 唯品會篩選菜單 | ![]() weipinhui.gif
|
| 一淘篩選菜單 | ![]() yitao.gif
|
我手機(jī)只有這么一些app了。。~ ~ 總之,目前的app的篩選樣式幾乎都能實(shí)現(xiàn),當(dāng)然細(xì)節(jié)要自己去調(diào)
用法(組裝全在一些代理里,代理方法可能有點(diǎn)多~ ~,不過只有兩個是必實(shí)現(xiàn)的,其他的都是可選的)
WMZDropMenuDelegate
@required 一定實(shí)現(xiàn)的方法
*/
- (NSArray*)titleArrInMenu:(WMZDropDownMenu *)menu;
/*
*返回WMZDropIndexPath每行 每列的數(shù)據(jù)
*/
- (NSArray*)menu:(WMZDropDownMenu *)menu
dataForRowAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
@optional 可選實(shí)現(xiàn)的方法
/*
*返回setion行標(biāo)題有多少列 默認(rèn)1列
*/
- (NSInteger)menu:(WMZDropDownMenu *)menu numberOfRowsInSection:
(NSInteger)section;
/*
*自定義tableviewCell內(nèi)容 默認(rèn)WMZDropTableViewCell 如果要使用默認(rèn)的
cell返回 nil
*/
- (UITableViewCell*)menu:(WMZDropDownMenu *)menu
cellForUITableView:(WMZDropTableView*)tableView AtIndexPath:
(NSIndexPath*)indexpath dataForIndexPath:(WMZDropTree*)model;
/*
*自定義tableView headView
*/
- (UITableViewHeaderFooterView*)menu:(WMZDropDownMenu *)menu
headViewForUITableView:(WMZDropTableView*)tableView
AtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*自定義tableView footView
*/
- (UITableViewHeaderFooterView*)menu:(WMZDropDownMenu *)menu
footViewForUITableView:(WMZDropTableView*)tableView
AtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*自定義collectionViewCell內(nèi)容
*/
- (UICollectionViewCell*)menu:(WMZDropDownMenu *)menu
cellForUICollectionView:(WMZDropCollectionView*)collectionView
AtDropIndexPath:(WMZDropIndexPath*)dropIndexPath AtIndexPath:
(NSIndexPath*)indexpath dataForIndexPath:(WMZDropTree*)model;
/*
*自定義collectionView headView
*/
- (UICollectionReusableView*)menu:(WMZDropDownMenu *)menu
headViewForUICollectionView:(WMZDropCollectionView*)collectionView
AtDropIndexPath:(WMZDropIndexPath*)dropIndexPath AtIndexPath:
(NSIndexPath*)indexpath;
/*
*自定義collectionView footView
*/
- (UICollectionReusableView*)menu:(WMZDropDownMenu *)menu
footViewForUICollectionView:(WMZDropCollectionView*)collectionView
AtDropIndexPath:(WMZDropIndexPath*)dropIndexPath AtIndexPath:
(NSIndexPath*)indexpath;
/*
*headView標(biāo)題
*/
- (NSString*)menu:(WMZDropDownMenu *)menu
titleForHeadViewAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*footView標(biāo)題
*/
- (NSString*)menu:(WMZDropDownMenu *)menu
titleForFootViewAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*返回WMZDropIndexPath每行 每列 indexpath的cell的高度 默認(rèn)35
*/
- (CGFloat)menu:(WMZDropDownMenu *)menu heightAtDropIndexPath:
(WMZDropIndexPath*)dropIndexPath AtIndexPath:
(NSIndexPath*)indexpath;
/*
*自定義headView高度 collectionView默認(rèn)35
*/
- (CGFloat)menu:(WMZDropDownMenu *)menu
heightForHeadViewAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*自定義footView高度
*/
- (CGFloat)menu:(WMZDropDownMenu *)menu
heightForFootViewAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
#pragma -mark 自定義用戶交互的每行的頭尾視圖
/*
*自定義每行全局頭部視圖 多用于交互事件
*/
- (UIView*)menu:(WMZDropDownMenu *)menu
userInteractionHeadViewInSection:(NSInteger)section;
/*
*自定義每行全局尾部視圖 多用于交互事件
*/
- (UIView*)menu:(WMZDropDownMenu *)menu
userInteractionFootViewInSection:(NSInteger)section;
#pragma -mark 樣式動畫相關(guān)代理
/*
*返回WMZDropIndexPath每行 每列的UI樣式 默認(rèn)MenuUITableView
注:設(shè)置了dropIndexPath.section 設(shè)置了 MenuUITableView 那么row則全部
為MenuUITableView 保持統(tǒng)一風(fēng)格
*/
- (MenuUIStyle)menu:(WMZDropDownMenu *)menu
uiStyleForRowIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*返回section行標(biāo)題數(shù)據(jù)視圖出現(xiàn)的動畫樣式 默認(rèn)
MenuShowAnimalBottom
注:最后一個默認(rèn)是篩選 彈出動畫為 MenuShowAnimalRight
*/
- (MenuShowAnimalStyle)menu:(WMZDropDownMenu *)menu
showAnimalStyleForRowInSection:(NSInteger)section;
/*
*返回section行標(biāo)題數(shù)據(jù)視圖消失的動畫樣式 默認(rèn) MenuHideAnimalTop
注:最后一個默認(rèn)是篩選 消失動畫為 MenuHideAnimalLeft
*/
- (MenuHideAnimalStyle)menu:(WMZDropDownMenu *)menu
hideAnimalStyleForRowInSection:(NSInteger)section;
/*
*返回WMZDropIndexPath每行 每列的編輯類型 單選|多選 默認(rèn)單選
*/
- (MenuEditStyle)menu:(WMZDropDownMenu *)menu
editStyleForRowAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*返回WMZDropIndexPath每行 每列 顯示的個數(shù)
注:
樣式MenuUITableView 默認(rèn)4個
樣式MenuUICollectionView 默認(rèn)1個 傳值無效
*/
- (NSInteger)menu:(WMZDropDownMenu *)menu
countForRowAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*WMZDropIndexPath是否顯示收縮功能 default >參數(shù)
wCollectionViewSectionShowExpandCount 顯示
*/
- (BOOL)menu:(WMZDropDownMenu *)menu
showExpandAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*WMZDropIndexPath上的內(nèi)容點(diǎn)擊 是否關(guān)閉視圖 default YES
*/
- (BOOL)menu:(WMZDropDownMenu *)menu
closeWithTapAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*是否關(guān)聯(lián) 其他標(biāo)題 即選中其他標(biāo)題 此標(biāo)題會不會取消選中狀態(tài) default
YES 取消,互不關(guān)聯(lián)
*/
- (BOOL)menu:(WMZDropDownMenu *)menu
dropIndexPathConnectInSection:(NSInteger)section;
#pragma -mark 交互自定義代理
/*
*cell點(diǎn)擊方法
*/
- (void)menu:(WMZDropDownMenu *)menu
didSelectRowAtDropIndexPath:(WMZDropIndexPath *)dropIndexPath
dataIndexPath:(NSIndexPath*)indexpath data:(WMZDropTree*)data;
/*
*標(biāo)題點(diǎn)擊方法
*/
- (void)menu:(WMZDropDownMenu *)menu didSelectTitleInSection:
(NSInteger)section btn:(WMZDropMenuBtn*)selectBtn;
/*
*確定方法 多個選擇
selectNoramalData 轉(zhuǎn)化后的的模型數(shù)據(jù)
selectData 字符串?dāng)?shù)據(jù)
*/
- (void)menu:(WMZDropDownMenu *)menu didConfirmAtSection:
(NSInteger)section selectNoramelData:(
NSMutableArray*)selectNoramalData selectStringData:
(NSMutableArray*)selectData;
/*
*自定義標(biāo)題按鈕視圖 返回配置 參數(shù)說明
offset 按鈕的間距
y 按鈕的y坐標(biāo) 自動會居中
*/
- (NSDictionary*)menu:(WMZDropDownMenu *)menu
customTitleInSection:
(NSInteger)section withTitleBtn:(WMZDropMenuBtn*)menuBtn;
/*
*自定義修改默認(rèn)collectionView尾部視圖
*/
- (void)menu:(WMZDropDownMenu *)menu
customDefauultCollectionFootView:(WMZDropConfirmView*)confirmView;
配置-鏈?zhǔn)秸Z法調(diào)用(都是可選實(shí)現(xiàn)的)
MenuTitle相關(guān)
| 參數(shù) | 類型 | 作用 (默認(rèn)值) |
|---|---|---|
| wBorderShow | BOOL | 標(biāo)題視圖是否顯示邊框 default NO |
| wFixBtnWidth | CGFLoat | 固定標(biāo)題的寬度 default 80 |
| wMenuTitleEqualCount | NSInteger | 標(biāo)題等分個數(shù) 用來控制標(biāo)題的寬度 default 4 |
| wMenuLine | BOOL | 標(biāo)題按鈕添加下劃線 dfault NO |
彈出視圖相關(guān)相關(guān)
| 參數(shù) | 類型 | 作用 (默認(rèn)值) |
|---|---|---|
| wFixDataViewHeight | CGFLoat | 固定彈出顯示數(shù)據(jù)層的高度 default 自動計算~>最大為屏幕高度的0.4倍 |
| wMainRadius | CGFLoat | 彈窗視圖的圓角 默認(rèn)0 |
| wMaxWidthScale | CGFLoat | 最大屏幕寬度系數(shù) default 0.9 |
| wMaxHeightScale | CGFLoat | 最大屏幕高度系數(shù) default 0.4 |
| wDefaultConfirmHeight | CGFLoat | 默認(rèn)確定重置視圖的高度 default 40 |
| wPopViewWidth | CGFLoat | 彈出動畫為pop時候 視圖的寬度 default 屏幕寬度/3 |
| wShadowColor | UIColor | 遮罩層顏色 default 333333 |
| wShadowAlpha | CGFLoat | 遮罩層透明度 default 0.4 |
| wShadowCanTap | BOOL | 遮罩層能否點(diǎn)擊 default YES |
| wShadowShow | BOOL | 遮罩層是否顯示 default YES |
tableview相關(guān)
| 參數(shù) | 類型 | 作用 (默認(rèn)值) |
|---|---|---|
| wTableViewColor | NSArray | tableview的顏色 default @[FFFFFF,F6F7FA,EBECF0,FFFFFF] |
| wTextAlignment | NSTextAlignment | cell文本居中樣式 default left |
| wCellSelectShowCheck | BOOL | tableViewCell 選中顯示打鉤圖片 default YES |
collectionView相關(guān)
| 參數(shù) | 類型 | 作用 (默認(rèn)值) |
|---|---|---|
| wReginerCollectionCells | NSArray | 注冊自定義的collectionViewCell 如果使用了自定義collectionView 必填否則會崩潰 |
| wReginerCollectionHeadViews | NSArray | 注冊自定義的collectionViewHeadView 如果使用了自定義collectionViewHeadView 必填 |
| wReginerCollectionFootViews | NSArray | 注冊自定義的collectionViewFoootView 如果使用了自定義collectionViewFoootView 必填 |
| wCollectionViewCellSpace | CGFloat | colletionCell的間距 default 10 |
| wCollectionViewCellBgColor | UIColor | colletionCell背景顏色 default 0x666666 |
| wCollectionViewCellTitleColor | UIColor | colletionCell文字顏色 default 0xf2f2f2 |
| wCollectionViewCellSelectBgColor | UIColor | colletionCell選中背景顏色 default 0xffeceb |
| wCollectionViewCellSelectTitleColor | UIColor | colletionCell選中文字顏色 default red |
| wCollectionViewCellBorderWith | CGFloat | colletionCell borderWidth default 0 |
| wCollectionViewSectionShowExpandCount | NSInteger | colletionView section 超過多少個cell顯示收縮按鈕 default 6 |
| wCollectionViewSectionRecycleCount | NSInteger | colletionView section 回收時候顯示的cell數(shù)量 default 0 |
| wCollectionViewDefaultFootViewMarginY | CGFloat | colletionViewFootView 距離底部的距離 默認(rèn)0 當(dāng)iphonex機(jī)型為 20 |
| wCollectionViewDefaultFootViewPaddingY | CGFloat | colletionViewFootView 距離頂部的距離 默認(rèn)0 |
內(nèi)容有點(diǎn)多 不過要兼容所有的篩選 需要開放很多接口出來自定義,~ ~
其他具體看demo
依賴
無任何依賴
安裝
CocoaPods
- 將 cocoapods 更新至最新版本.
- 在 Podfile 中添加
pod 'WMZDropDownMenu'。 - 執(zhí)行
pod install或pod update。 - 導(dǎo)入 #import "WMZDropDownMenu.h"。
注:要消除鏈?zhǔn)骄幊痰木?/h3>
要在Buildding Settings 把CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF 設(shè)為NO
手動安裝
- 下載 WMZDropDownMenu 文件夾內(nèi)的所有內(nèi)容。
- 將 WMZDropDownMenu 內(nèi)的源文件添加(拖放)到你的工程。
- 導(dǎo)入 #import "WMZDropDownMenu.h"
注意 配合WMZPageController使用+放在滾動視圖上的 需自定義彈出的y值如下
//動態(tài)高度
- (CGFloat)popFrameY{
if (!self.collectionSuperView) {
self.collectionSuperView = self.collectionView;
while (self.collectionSuperView.superview) {
self.collectionSuperView = self.collectionSuperView.superview;
}
}
CGRect rect = [self.collectionView convertRect:self.collectionView.superview.frame toView:self.collectionSuperView];
CGFloat y = rect.origin.y;
WMZPageController *pageVC = (WMZPageController*)self.parentViewController;
if (pageVC&&y<(Menu_NavigationBar+pageVC.param.titleHeight)) {
y = (Menu_NavigationBar+pageVC.param.titleHeight);
}
return y+self.menu.frame.size.height;
}
使用過程中如果有什么bug或者使用的問題歡迎給我提issue或者加我qq 我看到就會解決
GitHub地址










