iOS能實現任意電商或者其餘類型的篩選菜單控件

控件 WMZDropDownMenu

爲何寫這個控件?

主流的篩選菜單不少都是固定樣式的,不少時候要使用都要去改變源碼才能變成咱們想要的樣子,因而我就想寫一個控件,只須要調用代理就能實現幾乎全部功能的篩選功能git

實現功能

  • 組合自定義功能
  • 支持自定義多選|單選|複選
  • 支持自定義彈出的動畫 (目前已實現向下,向左全屏,向右全屏,拼多多對話框彈出,boss直聘全屏彈出)
  • 支持自定義tableView/collectionView頭尾視圖
  • 支持自定義全局頭尾視圖
  • 支持自定義collectionCell/tableViewCell視圖
  • 支持自定義標題
  • 支持自定義點擊回收視圖
  • 支持自定義回收列表
  • 支持任意級的聯動(因爲數據比較龐雜,暫時自動適配不了無限級的聯動,因此須要你調用一個方法更新數據傳給我,詳情看Demo)
  • 支持嵌套使用,即兩個篩選菜單能夠連着使用
  • 支持放在放在任意視圖上,tableviewHeadView毫無疑問支持且無須寫其餘代碼只要放上去便可
  • 支持控制器消失自動關閉視圖,無須再控制器消失方法裏手動關閉
  • 鏈式實現全部配置的自定義修改 (總之,你想要的基本都有,不想要的也有)

#目前已經用這控件實現的效果圖 ⚠️⚠️⚠️⚠️無須改變源碼 只須要調用個人代理組合功能便可⚠️⚠️⚠️⚠️github

仿閒魚篩選菜單

閒魚1.gif

仿美團篩選菜單

美團.gif

仿淘寶篩選菜單

淘寶.gif

餓了麼篩選菜單

餓了麼.gif

京東篩選菜單

京東.gif

拼多多篩選菜單

拼多多1.gif

簡書篩選菜單

簡書.gif

趕集網篩選菜單

趕集網.gif

美團外賣篩選菜單

美團外賣.gif

Boss直聘篩選菜單

Boss直聘.gif

惟品會篩選菜單

惟品會.gif

一淘篩選菜單

一淘.gif

#我手機只有這麼一些app了。。~ ~ 總之,目前的app的篩選樣式幾乎都能實現,固然細節要本身去調編程

用法(組裝全在一些代理裏,代理方法可能有點多~ ~,不過只有兩個是必實現的,其餘的都是可選的)

WMZDropMenuDelegate 
@required 必定實現的方法
*/
- (NSArray*)titleArrInMenu:(WMZDropDownMenu *)menu;
/*
*返回WMZDropIndexPath每行 每列的數據
*/
- (NSArray*)menu:(WMZDropDownMenu *)menu 
dataForRowAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
@optional 可選實現的方法
/*
*返回setion行標題有多少列 默認1列
*/
- (NSInteger)menu:(WMZDropDownMenu *)menu numberOfRowsInSection: 
 (NSInteger)section;
 /*
 *自定義tableviewCell內容 默認WMZDropTableViewCell 若是要使用默認的 
  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內容
 */
 - (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標題
*/
- (NSString*)menu:(WMZDropDownMenu *)menu 
titleForHeadViewAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
/*
*footView標題
*/
- (NSString*)menu:(WMZDropDownMenu *)menu 
titleForFootViewAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;


/*
*返回WMZDropIndexPath每行 每列 indexpath的cell的高度 默認35
*/
- (CGFloat)menu:(WMZDropDownMenu *)menu heightAtDropIndexPath: 
 (WMZDropIndexPath*)dropIndexPath AtIndexPath: 
 (NSIndexPath*)indexpath;
 /*
*自定義headView高度 collectionView默認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 樣式動畫相關代理
 /*
*返回WMZDropIndexPath每行 每列的UI樣式  默認MenuUITableView
 注:設置了dropIndexPath.section 設置了 MenuUITableView 那麼row則所有 
 爲MenuUITableView 保持統一風格
 */
 - (MenuUIStyle)menu:(WMZDropDownMenu *)menu 
 uiStyleForRowIndexPath:(WMZDropIndexPath*)dropIndexPath;
  /*
  *返回section行標題數據視圖出現的動畫樣式   默認 
  MenuShowAnimalBottom
  注:最後一個默認是篩選 彈出動畫爲 MenuShowAnimalRight
  */
  - (MenuShowAnimalStyle)menu:(WMZDropDownMenu *)menu 
  showAnimalStyleForRowInSection:(NSInteger)section;
  /*
  *返回section行標題數據視圖消失的動畫樣式   默認 MenuHideAnimalTop
  注:最後一個默認是篩選 消失動畫爲 MenuHideAnimalLeft
   */
   - (MenuHideAnimalStyle)menu:(WMZDropDownMenu *)menu 
  hideAnimalStyleForRowInSection:(NSInteger)section;
  /*
  *返回WMZDropIndexPath每行 每列的編輯類型 單選|多選  默認單選
  */
  - (MenuEditStyle)menu:(WMZDropDownMenu *)menu 
  editStyleForRowAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
  /*
  *返回WMZDropIndexPath每行 每列 顯示的個數
   注:
   樣式MenuUITableView         默認4個
   樣式MenuUICollectionView    默認1個 傳值無效
   */
   - (NSInteger)menu:(WMZDropDownMenu *)menu 
  countForRowAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;
  /*
  *WMZDropIndexPath是否顯示收縮功能 default >參數 
   wCollectionViewSectionShowExpandCount 顯示
    */
   - (BOOL)menu:(WMZDropDownMenu *)menu 
  showExpandAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;

  /*
  *WMZDropIndexPath上的內容點擊 是否關閉視圖 default YES
  */
  - (BOOL)menu:(WMZDropDownMenu *)menu 
  closeWithTapAtDropIndexPath:(WMZDropIndexPath*)dropIndexPath;

  /*
  *是否關聯 其餘標題 即選中其餘標題 此標題會不會取消選中狀態 default 
  YES 取消,互不關聯
  */
  - (BOOL)menu:(WMZDropDownMenu *)menu 
 dropIndexPathConnectInSection:(NSInteger)section;

 #pragma -mark 交互自定義代理
 /*
 *cell點擊方法
 */
  - (void)menu:(WMZDropDownMenu *)menu 
 didSelectRowAtDropIndexPath:(WMZDropIndexPath *)dropIndexPath
 dataIndexPath:(NSIndexPath*)indexpath data:(WMZDropTree*)data;
 /*
 *標題點擊方法
 */
 - (void)menu:(WMZDropDownMenu *)menu didSelectTitleInSection: 
(NSInteger)section btn:(WMZDropMenuBtn*)selectBtn;
 /*
 *肯定方法 多個選擇
  selectNoramalData 轉化後的的模型數據
 selectData 字符串數據
 */
 - (void)menu:(WMZDropDownMenu *)menu didConfirmAtSection: 
(NSInteger)section selectNoramelData:( 
NSMutableArray*)selectNoramalData selectStringData: 
(NSMutableArray*)selectData;


  /*
  *自定義標題按鈕視圖  返回配置 參數說明
  offset       按鈕的間距
  y            按鈕的y座標   自動會居中
 */
 - (NSDictionary*)menu:(WMZDropDownMenu *)menu  
 customTitleInSection: 
 (NSInteger)section withTitleBtn:(WMZDropMenuBtn*)menuBtn;

 /*
*自定義修改默認collectionView尾部視圖
*/
- (void)menu:(WMZDropDownMenu *)menu  
customDefauultCollectionFootView:(WMZDropConfirmView*)confirmView;
複製代碼

配置-鏈式語法調用(都是可選實現的)

MenuTitle相關

參數 類型 做用 (默認值)
wBorderShow BOOL 標題視圖是否顯示邊框 default NO
wFixBtnWidth CGFLoat 固定標題的寬度 default 80
wMenuTitleEqualCount NSInteger 標題等分個數 用來控制標題的寬度 default 4
wMenuLine BOOL 標題按鈕添加下劃線 dfault NO

###彈出視圖相關相關app

參數 類型 做用 (默認值)
wFixDataViewHeight CGFLoat 固定彈出顯示數據層的高度 default 自動計算~>最大爲屏幕高度的0.4倍
wMainRadius CGFLoat 彈窗視圖的圓角 默認0
wMaxWidthScale CGFLoat 最大屏幕寬度係數 default 0.9
wMaxHeightScale CGFLoat 最大屏幕高度係數 default 0.4
wDefaultConfirmHeight CGFLoat 默認肯定重置視圖的高度 default 40
wPopViewWidth CGFLoat 彈出動畫爲pop時候 視圖的寬度 default 屏幕寬度/3
wShadowColor UIColor 遮罩層顏色 default 333333
wShadowAlpha CGFLoat 遮罩層透明度 default 0.4
wShadowCanTap BOOL 遮罩層可否點擊 default YES
wShadowShow BOOL 遮罩層是否顯示 default YES

tableview相關

參數 類型 做用 (默認值)
wTableViewColor NSArray tableview的顏色 default @[FFFFFF,F6F7FA,EBECF0,FFFFFF]
wTextAlignment NSTextAlignment cell文本居中樣式 default left
wCellSelectShowCheck BOOL tableViewCell 選中顯示打鉤圖片 default YES

collectionView相關

參數 類型 做用 (默認值)
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數量 default 0
wCollectionViewDefaultFootViewMarginY CGFloat colletionViewFootView 距離底部的距離 默認0 當iphonex機型爲 20
wCollectionViewDefaultFootViewPaddingY CGFloat colletionViewFootView 距離頂部的距離 默認0

內容有點多 不過要兼容全部的篩選 須要開放不少接口出來自定義,~ ~

其餘具體看demo

依賴

無任何依賴iphone

安裝

CocoaPods

  1. 將 cocoapods 更新至最新版本.
  2. 在 Podfile 中添加 pod 'WMZDropDownMenu'
  3. 執行 pod installpod update
  4. 導入 #import "WMZDropDownMenu.h"。

注:要消除鏈式編程的警告

要在Buildding Settings 把CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF 設爲NOide

手動安裝

  1. 下載 WMZDropDownMenu 文件夾內的全部內容。
  2. 將 WMZDropDownMenu 內的源文件添加(拖放)到你的工程。
  3. 導入 #import "WMZDropDownMenu.h"

使用過程當中若是有什麼bug或者使用的問題歡迎給我提issue或者加我qq 我看到就會解決 以爲有用的話給個star GitHub地址動畫

相關文章
相關標籤/搜索