这是用于展示项目列表(水平表格)的扩展
将 EHHorizontalSelectionView 中的文件添加到您的项目中
#import <EHHorizontalSelectionView/EHHorizontalSelectionView.h>
您可以将 EHHorizontalSelectionView 作为 xib 或 storyboard 中的出口使用
@property (nonatomic, weak) IBOutlet EHHorizontalSelectionView * hSelView;
表格的默认样式是使用 EHHorizontalViewCell 单元格。要更改默认行为,您需要注册另一个单元格类或单元格 nib。自定义单元格必须从 EHHorizontalViewCell 衍生。
例如具有动画选择的单元格类型
[_hSelView registerCellWithClass:[EHHorizontalLineViewCell class]];
[_hSelView1 registerCellWithClass:[EHRoundedHorizontalViewCell class]];
或您的自定义单元格
[_hSelView2 registerCellNib:[UINib nibWithNibName:@"MyCustomCellNib" bundle:nil] withClass:[EHHorizontalViewCell class]];
设置委托
_hSelView1.delegate = self;
委托需要获取选择视图所需的数据
- (NSUInteger)numberOfItemsInHorizontalSelection:(EHHorizontalSelectionView*)hSelView
- (NSString *)titleForItemAtIndex:(NSUInteger)index forHorisontalSelection:(EHHorizontalSelectionView*)hSelView
以及接收选择事件
- (void)horizontalSelection:(EHHorizontalSelectionView * _Nonnull)hSelView didSelectObjectAtIndex:(NSUInteger)index;
当有 "UICollectionViewFlowLayout 的工作方式没有定义,因为:" 时可能有助于
self.automaticallyAdjustsScrollViewInsets = NO;
在 1.3.0 之后,您可以使用 IB 来更改选择视图的外观。提供了一套属性,可以更改视图的外观。 EHHorizontalSelcetionView 现在标记为 IBDesignable,您可以在 xib 或 storyboard 中看到自定义
您可以更改选定类型单元格的默认色调颜色
[EHHorizontalLineViewCell updateTintColor:[UIColor colorWithHex:0x00c264]];
您可以通过子类化该类型的单元格并重写方法 + (UIColor * _Nonnull)tintColor; 来实现
+ (UIColor *)tintColor
{
return [UIColor redColor];
}
或者您可以更改所选选择视图的着色颜色
[_hSelView2 setTintColor:[UIColor colorWithHex:0xff46c7]];
更改默认外观
[EHRoundedHorizontalViewCell updateFontMedium:[UIFont boldSystemFontOfSize:15]];
[EHRoundedHorizontalViewCell updateFont:[UIFont systemFontOfSize:15]];
更改所选选择视图
[_hSelView3 setFont:[UIFont systemFontOfSize:17]];
更改默认外观
[EHHorizontalLineViewCell updateCellGap:20];
更改所选选择视图
[_hSelView3 setCellGap:15.f];
[EHHorizontalLineViewCell updateColorHeight:2];
Danila Gusev