82 lines
2.5 KiB
C
82 lines
2.5 KiB
C
|
|
//
|
||
|
|
// MTGridSelectView.h
|
||
|
|
// MTGridSelectDemo
|
||
|
|
//
|
||
|
|
// Created by mambaxie on 2019/1/19.
|
||
|
|
// Copyright © 2019年 tencent. All rights reserved.
|
||
|
|
//
|
||
|
|
|
||
|
|
#import <UIKit/UIKit.h>
|
||
|
|
#import "MTGridSelectConfig.h"
|
||
|
|
|
||
|
|
NS_ASSUME_NONNULL_BEGIN
|
||
|
|
|
||
|
|
typedef NS_ENUM(NSUInteger, MTGridItemState) {
|
||
|
|
MTGridItemStateNormal,
|
||
|
|
MTGridItemStateSelected,
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
创建itemContentView完成后回调
|
||
|
|
|
||
|
|
@return 返回自定itemView 会被添加到itemContentView中
|
||
|
|
*/
|
||
|
|
typedef UIView *(^MTGridDidSetupItemContentViewBlock)(UIView *itemContentView, id itemModel);
|
||
|
|
/// changeByInner : 内部触发
|
||
|
|
typedef void(^MTGridItemStateChangedBlock)(UIView *itemView, id itemModel, MTGridItemState state, BOOL changeByInner);
|
||
|
|
|
||
|
|
/// 多选限制回调
|
||
|
|
typedef void(^MTGridMultipleSelectLimitBlock)(void);
|
||
|
|
|
||
|
|
@interface MTGridSelectView : UIView
|
||
|
|
|
||
|
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
||
|
|
@property (nonatomic, copy) NSArray<id> *originalModels;
|
||
|
|
/**
|
||
|
|
快速创建栅格选择view
|
||
|
|
|
||
|
|
@param itemModels item模型数组
|
||
|
|
@param setupConfigBlock 初始化配置
|
||
|
|
@param didSetupItemContentViewBlock 创建itemContentView完成后调用
|
||
|
|
@param itemStateChangedBlock item状态改变后调用
|
||
|
|
@param selectValueChangedBlock 选中值改变后调用
|
||
|
|
@return 栅格选择view
|
||
|
|
*/
|
||
|
|
+ (instancetype)gridSelectViewWithItemModels:(NSArray *)itemModels
|
||
|
|
setupConfig:(void(^)(MTGridSelectConfig *config))setupConfigBlock
|
||
|
|
didSetupItemContentView:(MTGridDidSetupItemContentViewBlock)didSetupItemContentViewBlock
|
||
|
|
itemStateChanged:(MTGridItemStateChangedBlock)itemStateChangedBlock
|
||
|
|
selectValueChanged:(void(^)(NSArray *selectedModels))selectValueChangedBlock;
|
||
|
|
|
||
|
|
/// 多选限制回调
|
||
|
|
@property (nonatomic, copy) MTGridMultipleSelectLimitBlock limitBlock;
|
||
|
|
|
||
|
|
/// 选中的item
|
||
|
|
@property (nonatomic, strong, readonly) NSArray<id> *selectedItems;
|
||
|
|
|
||
|
|
///
|
||
|
|
@property (nonatomic, assign, readonly) NSInteger itemTotalCount;
|
||
|
|
|
||
|
|
|
||
|
|
/// 选中指定下标
|
||
|
|
- (void)selectItemAtIndex:(NSInteger)index;
|
||
|
|
/// 选中多个指定下标
|
||
|
|
- (void)selectItemAtIndexs:(NSArray <NSNumber *>*)indexs;
|
||
|
|
/// 全选
|
||
|
|
- (void)selectAllItem;
|
||
|
|
/// 全不选
|
||
|
|
- (void)deselectAllItem;
|
||
|
|
|
||
|
|
/// 改变指定下标状态
|
||
|
|
- (void)changeItemStateAtIndex:(NSInteger)index state:(MTGridItemState)state;
|
||
|
|
/// 改变多个下标状态
|
||
|
|
- (void)changeItemStateAtIndexs:(NSArray <NSNumber *>*)index state:(MTGridItemState)state;
|
||
|
|
|
||
|
|
/// 刷新数据
|
||
|
|
- (void)reloadDataWithItemModels:(NSArray *)itemModels;
|
||
|
|
|
||
|
|
@end
|
||
|
|
|
||
|
|
NS_ASSUME_NONNULL_END
|