当前位置:   article > 正文

JXCategoryView的使用总结_jxcategorytitleview

jxcategorytitleview

一、初始化

-(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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

二、关联listContainerView

  • listContainerView 创建
-(JXCategoryListContainerView *)listContainerView{
    if (!_listContainerView) {
        _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
        _listContainerView.scrollView.scrollEnabled = YES;
    }
    return _listContainerView;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 与categoryView 建立关联
self.categoryView.listContainer = self.listContainerView;
  • 1
  • 实现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];
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

三、titles 重载

可以在初始化时指定titles属性赋值, 如果需要动态显示titles, 则可以在处理后,通过 reloadData 进行重载

  • 初始化时指定
_categoryView.titles = @[@"项目1",@"项目2"];
  • 1
  • 动态处理
NSArray *titles;
if (xxx) {
	titles = @[@"项目1",@"项目2"];
}else {
	titles = @[@"礼物1",@"礼物2"];
}
_categoryView.titles = titles;
[_categoryView reloadData];
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

四、设置指定项被选中

[self.categoryView selectItemAtIndex:0];
  • 1

五、代理方法

#pragma mark - JXCategoryViewDelegate -

//点击选中的情况才会调用该方法
- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
    
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

六、listContentView 需实现 listView 方法


@protocol JXCategoryListContentViewDelegate <NSObject>

/**
 如果列表是VC,就返回VC.view
 如果列表是View,就返回View自己

 @return 返回列表视图
 */
- (UIView *)listView;

@optional

/**
 可选实现,列表将要显示的时候调用
 */
- (void)listWillAppear;

/**
 可选实现,列表显示的时候调用
 */
- (void)listDidAppear;

/**
 可选实现,列表将要消失的时候调用
 */
- (void)listWillDisappear;

.....
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

根据协议声明来看, listView方法需要协议的实现者必须 实现才可以。 因为它是 @required (不指定,则为默认)声明的

#pragma mark - JXCategoryListContainerViewDelegate -
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index{
    __kindof UIViewController *vc  = self.controllers[index];
    return vc;
}
  • 1
  • 2
  • 3
  • 4
  • 5

- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index 这个回调需要返回实现了 JXCategoryListContentViewDelegate 的对象(一般是viewController)

@implementation MyContentViewController 

//实现 JXCategoryListContentViewDelegate 的代理方法
- (UIView *)listView{
    return self.view;
}

@end
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/787356
推荐阅读
相关标签
  

闽ICP备14008679号