Skip to content

Commit

Permalink
**V1.0.0** ---- 2016-6-21
Browse files Browse the repository at this point in the history
* 重大更新,最大程度简化dataSource
* 支持文字以及图片的选择状态记录
  • Loading branch information
stubbornness1219 committed Jun 21, 2016
1 parent c4c0917 commit c5819ec
Show file tree
Hide file tree
Showing 35 changed files with 289 additions and 264 deletions.
4 changes: 2 additions & 2 deletions EasyDropDownMenu.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

Pod::Spec.new do |s|
s.name = "EasyDropDownMenu"
s.version = "0.0.1"
s.version = "1.0.0"
s.summary = "类似美团,糯米,大众点评的筛选排序菜单"
s.description = <<-DESC
类似美团,糯米,大众点评的筛选排序菜单
类似美团,糯米,大众点评的筛选排序菜单,支持文字以及图片选择状态的记录
DESC
s.homepage = "https://github.com/stubbornnessness"
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
88 changes: 51 additions & 37 deletions EasyDropDownMenuTest/EasyDropDownMenuTest/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import EasyDropDownMenu

class ViewController: UIViewController, YXJDropDownMenuDelegate, YXJDropDownMenuDataSource {

lazy var classifys = ["美食", "今日新单", "电影", "酒店"]
lazy var cates = ["自助餐", "快餐", "火锅", "日韩料理", "西餐", "烧烤小吃"]
lazy var movices = ["内地剧", "港台剧", "英美剧"]
lazy var hostels = ["经济酒店", "商务酒店", "连锁酒店", "度假酒店", "公寓酒店"]
lazy var areas = ["全城", "芙蓉区", "雨花区", "天心区", "开福区", "岳麓区"]
lazy var sorts = ["默认排序", "离我最近", "好评优先", "人气优先", "最新发布"]
var classifys = [YXJCellData]()
var cates = [YXJCellData]()
var movices = [YXJCellData]()
var hostels = [YXJCellData]()
var areas = [YXJCellData]()
var sorts = [YXJCellData]()

lazy var menu = YXJDropDownMenu.init(origin: CGPointMake(0, 64), andHeight: 44)

Expand All @@ -25,6 +25,41 @@ class ViewController: UIViewController, YXJDropDownMenuDelegate, YXJDropDownMenu

// self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title:"重新加载", style:UIBarButtonItemStyle.Plain, target:self, action:"menuReloadData")

classifys.append(YXJCellData(title: "美食", detailText: "1", defaultImage: UIImage(named: "TestImgs.bundle/0"), selectImage: UIImage(named: "TestImgs.bundle/0_select")))
classifys.append(YXJCellData(title: "今日新单", detailText: "2", defaultImage: UIImage(named: "TestImgs.bundle/1"), selectImage: UIImage(named: "TestImgs.bundle/1_select")))
classifys.append(YXJCellData(title: "电影", detailText: "3", defaultImage: UIImage(named: "TestImgs.bundle/2"), selectImage: UIImage(named: "TestImgs.bundle/2_select")))
classifys.append(YXJCellData(title: "酒店", detailText: "4", defaultImage: UIImage(named: "TestImgs.bundle/3"), selectImage: UIImage(named: "TestImgs.bundle/3_select")))

cates.append(YXJCellData(title: "自助餐", detailText: "1", defaultImage: UIImage(named: "TestImgs.bundle/5"), selectImage: UIImage(named: "TestImgs.bundle/5_select")))
cates.append(YXJCellData(title: "快餐", detailText: "2", defaultImage: UIImage(named: "TestImgs.bundle/4"), selectImage: UIImage(named: "TestImgs.bundle/4_select")))
cates.append(YXJCellData(title: "火锅", detailText: "3", defaultImage: UIImage(named: "TestImgs.bundle/3"), selectImage: UIImage(named: "TestImgs.bundle/3_select")))
cates.append(YXJCellData(title: "日韩料理", detailText: "4", defaultImage: UIImage(named: "TestImgs.bundle/2"), selectImage: UIImage(named: "TestImgs.bundle/2_select")))
cates.append(YXJCellData(title: "西餐", detailText: "5", defaultImage: UIImage(named: "TestImgs.bundle/1"), selectImage: UIImage(named: "TestImgs.bundle/1_select")))
cates.append(YXJCellData(title: "烧烤小吃", detailText: "6", defaultImage: UIImage(named: "TestImgs.bundle/0"), selectImage: UIImage(named: "TestImgs.bundle/0_select")))

movices.append(YXJCellData(title: "内地剧", detailText: "2", defaultImage: UIImage(named: "TestImgs.bundle/4"), selectImage: UIImage(named: "TestImgs.bundle/4_select")))
movices.append(YXJCellData(title: "港台剧", detailText: "3", defaultImage: UIImage(named: "TestImgs.bundle/3"), selectImage: UIImage(named: "TestImgs.bundle/3_select")))
movices.append(YXJCellData(title: "英美剧", detailText: "4", defaultImage: UIImage(named: "TestImgs.bundle/2"), selectImage: UIImage(named: "TestImgs.bundle/2_select")))

hostels.append(YXJCellData(title: "经济酒店", detailText: "5", defaultImage: UIImage(named: "TestImgs.bundle/5"), selectImage: UIImage(named: "TestImgs.bundle/5_select")))
hostels.append(YXJCellData(title: "商务酒店", detailText: "4", defaultImage: UIImage(named: "TestImgs.bundle/4"), selectImage: UIImage(named: "TestImgs.bundle/4_select")))
hostels.append(YXJCellData(title: "连锁酒店", detailText: "3", defaultImage: UIImage(named: "TestImgs.bundle/3"), selectImage: UIImage(named: "TestImgs.bundle/3_select")))
hostels.append(YXJCellData(title: "度假酒店", detailText: "2", defaultImage: UIImage(named: "TestImgs.bundle/2"), selectImage: UIImage(named: "TestImgs.bundle/2_select")))
hostels.append(YXJCellData(title: "公寓酒店", detailText: "1", defaultImage: UIImage(named: "TestImgs.bundle/1"), selectImage: UIImage(named: "TestImgs.bundle/1_select")))

areas.append(YXJCellData(title: "全城", detailText: nil, defaultImage: UIImage(named: "TestImgs.bundle/5"), selectImage: UIImage(named: "TestImgs.bundle/5_select")))
areas.append(YXJCellData(title: "芙蓉区", detailText: nil, defaultImage: UIImage(named: "TestImgs.bundle/4"), selectImage: UIImage(named: "TestImgs.bundle/4_select")))
areas.append(YXJCellData(title: "雨花区", detailText: nil, defaultImage: UIImage(named: "TestImgs.bundle/3"), selectImage: UIImage(named: "TestImgs.bundle/3_select")))
areas.append(YXJCellData(title: "天心区", detailText: nil, defaultImage: UIImage(named: "TestImgs.bundle/2"), selectImage: UIImage(named: "TestImgs.bundle/2_select")))
areas.append(YXJCellData(title: "开福区", detailText: nil, defaultImage: UIImage(named: "TestImgs.bundle/1"), selectImage: UIImage(named: "TestImgs.bundle/1_select")))
areas.append(YXJCellData(title: "岳麓区", detailText: nil, defaultImage: UIImage(named: "TestImgs.bundle/0"), selectImage: UIImage(named: "TestImgs.bundle/0_select")))

sorts.append(YXJCellData(title: "默认排序", detailText: nil, defaultImage: nil, selectImage: nil))
sorts.append(YXJCellData(title: "离我最近", detailText: nil, defaultImage: nil, selectImage: nil))
sorts.append(YXJCellData(title: "好评优先", detailText: nil, defaultImage: nil, selectImage: nil))
sorts.append(YXJCellData(title: "人气优先", detailText: nil, defaultImage: nil, selectImage: nil))
sorts.append(YXJCellData(title: "最新发布", detailText: nil, defaultImage: nil, selectImage: nil))

// 添加下拉菜单
self.menu.delegate = self
self.menu.dataSource = self
Expand All @@ -39,7 +74,10 @@ class ViewController: UIViewController, YXJDropDownMenuDelegate, YXJDropDownMenu

// MARK:右键点击事件
func menuReloadData() {
self.classifys = ["美食", "今日新单", "电影"]
self.classifys.removeAll()
classifys.append(YXJCellData(title: "今日新单", detailText: "2", defaultImage: UIImage(named: "1"), selectImage: UIImage(named: "1_select")))
classifys.append(YXJCellData(title: "电影", detailText: "3", defaultImage: UIImage(named: "2"), selectImage: UIImage(named: "2_select")))
classifys.append(YXJCellData(title: "酒店", detailText: "4", defaultImage: UIImage(named: "3"), selectImage: UIImage(named: "3_select")))
self.menu.reloadData()
}
// MARK:按钮事件
Expand All @@ -60,7 +98,7 @@ class ViewController: UIViewController, YXJDropDownMenuDelegate, YXJDropDownMenu
return self.sorts.count
}
}
func menu(menu: YXJDropDownMenu!, titleForRowAtIndexPath indexPath: YXJIndexPath!) -> String! {
func menu(menu: YXJDropDownMenu!, configRowAtIndexPath indexPath: YXJIndexPath!) -> YXJCellData! {
if (indexPath.column == 0) {
return self.classifys[indexPath.row]
} else if (indexPath.column == 1) {
Expand All @@ -69,31 +107,6 @@ class ViewController: UIViewController, YXJDropDownMenuDelegate, YXJDropDownMenu
return self.sorts[indexPath.row]
}
}

// MARK: new datasource
func menu(menu: YXJDropDownMenu!, imageNameForRowAtIndexPath indexPath: YXJIndexPath!) -> UIImage! {
if (indexPath.column == 0 || indexPath.column == 1) {
return UIImage(named: "TestImgs.bundle/ic_filter_category_\(indexPath.row)")
}
return nil
}
func menu(menu: YXJDropDownMenu!, imageNameForItemsInRowAtIndexPath indexPath: YXJIndexPath!) -> UIImage! {
if (indexPath.column == 0 || indexPath.column == 1) {
return UIImage(named: "TestImgs.bundle/ic_filter_category_\(indexPath.item)")
}
return nil
}

// MARK: new datasource
func menu(menu: YXJDropDownMenu!, detailTextForRowAtIndexPath indexPath: YXJIndexPath!) -> String! {
if (indexPath.column < 2) {
return "11"
}
return nil
}
func menu(menu: YXJDropDownMenu!, detailTextForItemsInRowAtIndexPath indexPath: YXJIndexPath!) -> String! {
return "22"
}
func menu(menu: YXJDropDownMenu!, numberOfItemsInRow row: Int, column: Int) -> Int {
if (column == 0) {
if (row == 0) {
Expand All @@ -106,15 +119,16 @@ class ViewController: UIViewController, YXJDropDownMenuDelegate, YXJDropDownMenu
}
return 0
}
func menu(menu: YXJDropDownMenu!, titleForItemsInRowAtIndexPath indexPath: YXJIndexPath!) -> String! {
func menu(menu: YXJDropDownMenu!, configItemsInRowAtIndexPath indexPath: YXJIndexPath!) -> YXJCellData! {
if (indexPath.column == 0) {
if (indexPath.row == 0) {
return self.cates[indexPath.item]
return cates[indexPath.item]
} else if (indexPath.row == 2) {
return self.movices[indexPath.item]
return movices[indexPath.item]
} else if (indexPath.row == 3) {
return self.hostels[indexPath.item]
return hostels[indexPath.item]
}

}
return nil
}
Expand Down
Binary file modified EasyDropDownMenuTest/EasyDropDownMenuTest/test.gif
3 changes: 3 additions & 0 deletions EasyDropDownMenuTest/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 16 additions & 19 deletions Pod/YXJDropDownMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <UIKit/UIKit.h>

#pragma mark - indexPath
@interface YXJIndexPath : NSObject

@property (nonatomic, assign) NSInteger column;
Expand All @@ -23,7 +24,15 @@

@end

@interface YXJBackgroundCellView : UIView
#pragma mark - YXJCellData
@interface YXJCellData:NSObject

@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *detailText;
@property (nonatomic, strong) UIImage *defaultImage;
@property (nonatomic, strong) UIImage *selectImage;

- (instancetype)initWithTitle:(NSString *)title detailText:(NSString *)detailText defaultImage:(UIImage *)defaultImage selectImage:(UIImage *)selectImage;

@end

Expand All @@ -36,30 +45,18 @@
/** 返回 menu 第column列有多少行 */
- (NSInteger)menu:(YXJDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column;

/** 返回 menu 第column列 每行title */
- (NSString *)menu:(YXJDropDownMenu *)menu titleForRowAtIndexPath:(YXJIndexPath *)indexPath;
/** 返回 menu 第column列 每行data */
- (YXJCellData *)menu:(YXJDropDownMenu *)menu configRowAtIndexPath:(YXJIndexPath *)indexPath;

@optional
/** 返回 menu 有多少列 ,默认1列 */
- (NSInteger)numberOfColumnsInMenu:(YXJDropDownMenu *)menu;

/** 返回 menu 第column列 每行image */
- (UIImage *)menu:(YXJDropDownMenu *)menu imageNameForRowAtIndexPath:(YXJIndexPath *)indexPath;

/** detailText ,right text */
- (NSString *)menu:(YXJDropDownMenu *)menu detailTextForRowAtIndexPath:(YXJIndexPath *)indexPath;

/** 当有column列 row行 返回有多少个item ,如果>0,说明有二级列表 ,=0 没有二级列表,如果都没有可以不实现该协议 */
- (NSInteger)menu:(YXJDropDownMenu *)menu numberOfItemsInRow:(NSInteger)row column:(NSInteger)column;

/** 当有column列 row行 item项 title , 如果都没有可以不实现该协议 */
- (NSString *)menu:(YXJDropDownMenu *)menu titleForItemsInRowAtIndexPath:(YXJIndexPath *)indexPath;

/** 当有column列 row行 item项 image */
- (UIImage *)menu:(YXJDropDownMenu *)menu imageNameForItemsInRowAtIndexPath:(YXJIndexPath *)indexPath;

/** detailText ,right text */
- (NSString *)menu:(YXJDropDownMenu *)menu detailTextForItemsInRowAtIndexPath:(YXJIndexPath *)indexPath;
- (YXJCellData *)menu:(YXJDropDownMenu *)menu configItemsInRowAtIndexPath:(YXJIndexPath *)indexPath;

@end

Expand Down Expand Up @@ -93,7 +90,7 @@
@property (nonatomic, assign) BOOL isClickHaveItemValid;

@property (nonatomic, getter=isRemainMenuTitle) BOOL remainMenuTitle; // 切换条件时是否更改menu title
@property (nonatomic, strong) NSMutableArray *currentSelectRowArray; // 恢复默认选项用
@property (nonatomic, strong) NSMutableArray *selectArray; // 记录每个column选中的raw和item

/**
* 默认宽度为屏幕宽度
Expand All @@ -103,8 +100,8 @@
*/
- (instancetype)initWithOrigin:(CGPoint)origin andHeight:(CGFloat)height;

// 获取title
- (NSString *)titleForRowAtIndexPath:(YXJIndexPath *)indexPath;
// 获取data
- (YXJCellData *)dataForRowAtIndexPath:(YXJIndexPath *)indexPath;

// 重新加载数据
- (void)reloadData;
Expand Down
Loading

0 comments on commit c5819ec

Please sign in to comment.