cdts/xdts-ios 3/TreeHole/Code/Utility/MTCommonListTable/MTCommonListTableConfig.h
2023-07-27 09:20:00 +08:00

185 lines
9.0 KiB
Objective-C
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// MTCommonListTableConfig.h
// MTCommonListTable
//
// Created by ko1o on 2018/8/29.
// Copyright © 2018年 ko1o. All rights reserved.
//
#import <UIKit/UIKit.h>
#define MTNullElement [NSNull null]
typedef NS_ENUM(NSUInteger, MTCommonListTableCellStyle) {
MTCommonListTableCellStyleNone,
MTCommonListTableCellStyleDisclosureIndicator,
MTCommonListTableCellStyleDetailButton,
MTCommonListTableCellStyleCheckmark,
MTCommonListTableCellStyleSwitch,
MTCommonListTableCellStyleCenterLabelAction // 文字居中 处理事件(如微信的推出登录)
};
typedef NS_ENUM(NSUInteger, MTCommonListTableCellSeparatorLeadingType) {
MTCommonListTableCellSeparatorLeadingTypeLeadLeftmostItem,
MTCommonListTableCellSeparatorLeadingTypeZero,
MTCommonListTableCellSeparatorLeadingTypeLeadingImage,
MTCommonListTableCellSeparatorLeadingTypeLeadingTitle,
};
@class MTCommonListTableViewCell, MTCommonListTableViewController, MTCommonListTableConfig, MTCommonListTableCellConfig;
typedef void(^MTCommonListTableCellDidSelectBlock)(MTCommonListTableViewController *tableViewController, NSIndexPath *indexPath, MTCommonListTableCellConfig *cellConfig);
typedef void(^MTCommonListTableCellSwitchButtonChangeValueBlcok)(UISwitch *switchButton, MTCommonListTableViewCell *cell);
typedef void(^MTCommonListTableCellDidLayoutSubviewsBlcok)(MTCommonListTableViewCell *cell);
@interface MTCommonListTableCellConfig : NSObject <NSCopying>
@property (nonatomic, weak) MTCommonListTableConfig *tableConfig;
// 自定义cell
@property (nonatomic, strong) UITableViewCell *customCell;
// for all style
@property (nonatomic, copy) NSString *iconImageName;
@property (nonatomic, strong) UIColor *backgroundColor;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *accessoryTitle;
@property (nonatomic, assign) UITableViewCellSelectionStyle selectionStyle;
@property (nonatomic, assign) UITableViewCellAccessoryType accessoryType;
@property (nonatomic, strong) UIView *accessoryView;
@property (nonatomic, weak) MTCommonListTableViewCell *cell;
@property (nonatomic, assign) MTCommonListTableCellStyle style;
@property (nonatomic, strong) UIColor *imageTintColor;
@property (nonatomic, strong) MTCommonListTableCellDidLayoutSubviewsBlcok didLayoutSubviewsAction;
// 以下这些属性如果为nil 使用table config 默认配置
@property (nonatomic, copy) MTCommonListTableCellDidSelectBlock cellAction;
@property (nonatomic, strong) UIFont *titleFont;
@property (nonatomic, strong) UIColor *titleColor;
@property (nonatomic, assign) CGFloat imageMarginLeft;
@property (nonatomic, assign) CGSize imageSize;
@property (nonatomic, assign) CGFloat imageCornerRadius;
@property (nonatomic, assign) CGFloat titleAndImageMargin;
@property (nonatomic, strong) UIColor *accessoryTitleColor;
@property (nonatomic, strong) UIFont *accessoryTitleFont;
@property (nonatomic, copy) NSString *accessoryImageName;
@property (nonatomic, copy) NSString *accessoryCheckMarkImageName;
@property (nonatomic, copy) NSString *accessoryDetailImageName;
@property (nonatomic, copy) NSString *accessoryDisclosureIndicatorImageName;
@property (nonatomic, assign) CGFloat accessoryTitleAndImageMargin;
@property (nonatomic, assign) CGSize accessoryImageSize;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) MTCommonListTableCellSeparatorLeadingType separatorLeadingType;
@property (nonatomic, assign) CGFloat separatorMarginLeft;
// for `MTCommonListTableCellStyleSwitch`
@property (nonatomic, strong) UISwitch *switchButton;
@property (nonatomic, strong) UIColor *accessorySwitchButtonOnTintColor;
@property (nonatomic, copy) MTCommonListTableCellSwitchButtonChangeValueBlcok switchButtonAction;
// for `MTCommonListTableCellStyleCheckmark`
@property (nonatomic, assign) BOOL checked;
+ (instancetype)defaultConfig;
+ (instancetype)configWithStyle:(MTCommonListTableCellStyle)style;
@end
@interface MTCommonListTableSectionConfig : NSObject
@property (nonatomic, weak) MTCommonListTableConfig *tableConfig;
@property (nonatomic, copy) NSAttributedString *headerAttributedTitle;
@property (nonatomic, copy) NSString *headerTitle;
@property (nonatomic, strong) UIFont *headerTitleFont;
@property (nonatomic, strong) UIColor *headerTitleColor;
@property (nonatomic, assign) UIEdgeInsets headerInset;
@property (nonatomic, assign) CGFloat headerHeight;
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, copy) NSAttributedString *footerAttributedTitle;
@property (nonatomic, copy) NSString *footerTitle;
@property (nonatomic, strong) UIFont *footerTitleFont;
@property (nonatomic, strong) UIColor *footerTitleColor;
@property (nonatomic, assign) UIEdgeInsets footerInset;
@property (nonatomic, assign) CGFloat footerHeight;
@property (nonatomic, strong) UIView *footerView;
@property (nonatomic, strong) NSArray<MTCommonListTableCellConfig *> *cellConfigs;
+ (instancetype)defaultConfig;
@end
@interface MTCommonListTableConfig : NSObject
@property (nonatomic, copy) NSString *tableTitle;
@property (nonatomic, strong) UIColor *tableBackgroundColor;
@property (nonatomic, copy) NSArray *sectionConfigs;
@property (nonatomic, assign) UITableViewCellSeparatorStyle separatorStyle;
@property (nonatomic, assign) UITableViewStyle tableStyle;
@property (nonatomic, assign) UIEdgeInsets tableContentInset;
// 对所有cell生效 优先级低于cellConfig
@property (nonatomic, assign) CGFloat cellImageMarginLeft;
@property (nonatomic, assign) CGFloat cellTitleAndImageMargin;
@property (nonatomic, assign) CGSize cellImageSize;
@property (nonatomic, strong) UIColor *cellImageTintColor;
@property (nonatomic, strong) UIColor *cellBackgroudColor;
@property (nonatomic, assign) CGFloat cellImageCornerRadius;
@property (nonatomic, strong) UIFont *cellTitleFont;
@property (nonatomic, strong) UIColor *cellTitleColor;
@property (nonatomic, strong) UIColor *cellAccessoryTitleColor;
@property (nonatomic, strong) UIFont *cellAccessoryTitleFont;
@property (nonatomic, assign) CGFloat cellAccessoryTitleAndImageMargin;
@property (nonatomic, assign) CGSize cellAccessoryImageSize;
@property (nonatomic, copy) NSString *cellAccessoryImageName;
@property (nonatomic, copy) NSString *cellAccessoryCheckMarkImageName;
@property (nonatomic, copy) NSString *cellAccessoryDetailImageName;
@property (nonatomic, copy) NSString *cellAccessoryDisclosureIndicatorImageName;
@property (nonatomic, assign) CGFloat cellHeight;
@property (nonatomic, copy) MTCommonListTableCellDidSelectBlock cellAction;
@property (nonatomic, assign) MTCommonListTableCellSeparatorLeadingType cellSeparatorLeadingType;
@property (nonatomic, assign) CGFloat separatorMarginLeft; // 优先级高于cellSeparatorLeadingType
// 对所有section生效 优先级低于sectionConfig
@property (nonatomic, copy) NSString *sectionHeaderTitle;
@property (nonatomic, strong) UIFont *sectionHeaderTitleFont;
@property (nonatomic, strong) UIColor *sectionHeaderTitleColor;
@property (nonatomic, assign) CGFloat sectionHeaderHeight;
@property (nonatomic, assign) UIEdgeInsets sectionHeaderInset;
@property (nonatomic, copy) NSString *sectionFooterTitle;
@property (nonatomic, strong) UIFont *sectionFooterTitleFont;
@property (nonatomic, strong) UIColor *sectionFooterTitleColor;
@property (nonatomic, assign) UIEdgeInsets sectionFooterInset;
@property (nonatomic, assign) CGFloat sectionFooterHeight;
// 对所有section生效 优先级低于sectionConfig
// Note如果section无数据请使用`MTNullElement`占位!
@property (nonatomic, copy) NSArray *sectionHeaderTitles;
@property (nonatomic, copy) NSArray *sectionFooterTitles;
@property (nonatomic, copy) NSArray *cellTitles;
@property (nonatomic, copy) NSArray *cellImageNames;
// 用于全局默认配置,通过该方法自定义默认配置
+ (instancetype)sharedConfig;
// 快速根据创建配置 eg. rowsArr = @[@3, @2, @5];
+ (instancetype)defaultConfigWithRowsCountForSections:(NSArray<NSNumber *> *)rowsCountArr;
+ (instancetype)defaultConfigWithCellStyle:(MTCommonListTableCellStyle)style rowsCountForSections:(NSArray<NSNumber *> *)rowsCountArr;
+ (instancetype)defaultConfigWithCellConfig:(MTCommonListTableCellConfig *)cellConfig rowsCountForSections:(NSArray<NSNumber *> *)rowsCountArr;
// 必须保证sectionConfigs有值 才可设置指定cell的config
- (void)resetCellConfigForSection:(NSInteger)section row:(NSInteger)row config:(void(^)(MTCommonListTableCellConfig *cellConfig))config;
- (void)resetCellConfigForRowsAtIndexPaths:(NSArray <NSIndexPath *>*)indexPaths config:(void(^)(MTCommonListTableCellConfig *config ,NSIndexPath *indexPath))config;
- (MTCommonListTableCellConfig *)cellConfigForSection:(NSInteger)section row:(NSInteger)row;
// 必须保证sectionConfigs有值 才可设置指定cell的config
- (void)resetSectionConfigForSection:(NSInteger)section config:(void(^)(MTCommonListTableSectionConfig *sectionConfig))config;
- (void)resetSectionConfigForSections:(NSArray <NSNumber *>*)sections config:(void(^)(MTCommonListTableSectionConfig *sectionConfig))config;
- (MTCommonListTableSectionConfig *)sectionConfigForSection:(NSInteger)section;
@end