赞
踩
-(JXCategoryTitleView *)categoryView{ if (!_categoryView) { _categoryView = [[JXCategoryTitleView alloc] init]; _categoryView.delegate = self; _categoryView.titleDataSource = self; _categoryView.averageCellSpacingEnabled = NO; //是否平均分配项目之间的间距 _categoryView.contentEdgeInsetLeft = 24; //靠左显示的边距 _categoryView.titleLabelVerticalOffset = -5; //标题向上偏移 _categoryView.cellSpacing = 32; //固定分类项之前的间距 _categoryView.titles = @[]; _categoryView.defaultSelectedIndex = 0; //默认选中 _categoryView.titleColor = RGBA(119, 119, 119, 1); //默认文字颜色 _categoryView.titleSelectedColor = RGBA(51, 51, 51, 1); //文字选择颜色 _categoryView.backgroundColor = [UIColor clearColor]; _categoryView.titleFont = AppFont(16); _categoryView.titleSelectedFont = AppBoldFont(16); //底部指示器 JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init]; lineView.verticalMargin = 10; //默认底部,越大越向上偏移 lineView.indicatorHeight = 3; //指示器高度 lineView.indicatorCornerRadius = 0; //是否倒圆角 lineView.indicatorColor = RGBA(72, 142, 255, 1); //指示器颜色 lineView.indicatorWidth = 24; //指示器宽度 lineView.scrollStyle = JXCategoryIndicatorScrollStyleSameAsUserScroll; //指示器滚动样式 _categoryView.indicators = @[lineView]; } return _categoryView; }
-(JXCategoryListContainerView *)listContainerView{
if (!_listContainerView) {
_listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
_listContainerView.scrollView.scrollEnabled = YES;
}
return _listContainerView;
}
self.categoryView.listContainer = self.listContainerView;
listContainerView
代理//子控制器数组 - (NSArray<__kindof UIViewController *> *)controllers{ return @[ self.VC1, self.VC2, ]; } #pragma mark - JXCategoryListContainerViewDelegate - - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index{ __kindof UIViewController *vc = self.controllers[index]; return vc; } - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView { return self.controllers.count; } //定义scrollerview处理手势冲突 - (Class)scrollViewClassInlistContainerView:(JXCategoryListContainerView *)listContainerView{ return [ServiceScrollView class]; }
可以在初始化时指定titles
属性赋值, 如果需要动态显示titles, 则可以在处理后,通过 reloadData
进行重载
_categoryView.titles = @[@"项目1",@"项目2"];
NSArray *titles;
if (xxx) {
titles = @[@"项目1",@"项目2"];
}else {
titles = @[@"礼物1",@"礼物2"];
}
_categoryView.titles = titles;
[_categoryView reloadData];
[self.categoryView selectItemAtIndex:0];
#pragma mark - JXCategoryViewDelegate -
//点击选中的情况才会调用该方法
- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
}
listContentView
需实现 listView 方法@protocol JXCategoryListContentViewDelegate <NSObject> /** 如果列表是VC,就返回VC.view 如果列表是View,就返回View自己 @return 返回列表视图 */ - (UIView *)listView; @optional /** 可选实现,列表将要显示的时候调用 */ - (void)listWillAppear; /** 可选实现,列表显示的时候调用 */ - (void)listDidAppear; /** 可选实现,列表将要消失的时候调用 */ - (void)listWillDisappear; .....
根据协议声明来看, listView
方法需要协议的实现者必须 实现才可以。 因为它是 @required
(不指定,则为默认)声明的
#pragma mark - JXCategoryListContainerViewDelegate -
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index{
__kindof UIViewController *vc = self.controllers[index];
return vc;
}
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index
这个回调需要返回实现了 JXCategoryListContentViewDelegate
的对象(一般是viewController)
@implementation MyContentViewController
//实现 JXCategoryListContentViewDelegate 的代理方法
- (UIView *)listView{
return self.view;
}
@end
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。