赞
踩
//遵守协议
@interface ViewController () <JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>
@property (nonatomic ,retain) JXCategoryTitleView *categoryView;
@property (nonatomic ,retain) JXCategoryListContainerView *listContainerView;
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UIView *midView;
@end
//初始化 JXCategoryTitleView:
self.categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, self.topView.bounds.size.width, 50)];
//代理
self.categoryView.delegate = self;
//配置属性
self.categoryView.titles = @[@"螃蟹", @"麻辣小龙虾", @"苹果"];
//title的颜色是否渐变过渡 默认NO
self.categoryView.titleColorGradientEnabled = YES;
//下划线
JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
lineView.indicatorColor = [UIColor redColor];
lineView.indicatorWidth = JXCategoryViewAutomaticDimension;
//配置titleView的下划线
self.categoryView.indicators = @[lineView];
[self.topView addSubview:self.categoryView];
//实现 JXCategoryViewDelegate 代理(可选)
// 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index;
// 点击选中的情况才会调用该方法
- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index;
// 滚动选中的情况才会调用该方法
- (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index;
// 正在滚动中的回调
- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio;
JXCategoryListContainerView
是对列表视图高度封装的类,具有以下优点:
UIScrollView
自定义,封装度高、代码集中、使用简单;willAppear、didAppear、willDisappear、didDisappear
生命周期方法调用; //初始化JXCategoryListContainerView并关联到categoryView
//设置下面的
self.listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
//记得配置Frame
self.listContainerView.frame = CGRectMake(0, 0, self.midView.frame.size.width, self.midView.frame.size.height);
[self.midView addSubview:self.listContainerView];
// 关联到categoryView
self.categoryView.listContainer = self.listContainerView;
JXCategoryListContainerViewDelegate
代理方法:// 返回列表的数量
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
return self.titles.count;
}
// 根据下标 index 返回对应遵守并实现 `JXCategoryListContentViewDelegate` 协议的列表实例
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
//这里需要返回一个遵守JXCategoryListContentViewDelegate的对象 例如自己写一个JJVC
JJViewController *vc = [[JJViewController alloc]init];
return vc;
}
JXCategoryListContentViewDelegate
的类, 不管是继承 UIView
还是 UIViewController
都可以,提高使用灵活性,更便于现有的业务接入。// 返回列表视图
// 如果列表是 VC,就返回 VC.view
// 如果列表是 View,就返回 View 自己
- (UIView *)listView {
return self.view;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。