JXCategoryTitleView的使用

最近写项目,遇到了一个vc下面有多个vc 指示器可以点击切换,也可也左右滑动进行切换,解除了JXCategoryTitleView  感觉很好用;

一般要求主vc遵循JXCategoryViewDelegate、JXCategoryListContainerViewDelegate两个协议 子vc遵循JXCategoryListContentViewDelegate

必写属性

//指示器view
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
//正文view
@property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
//vc数组 直接添加成vc可使得代码更加简洁
@property (strong, nonatomic) NSArray <__kindof UIViewController *> *controllers;

遵循协议 则相对应的代理方法必写

#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView{
    return self.view;
}
#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;
}
#pragma mark - JXCategoryViewDelegate
// 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index { 
    //侧滑手势处理
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}

- (BOOL)categoryCollectionView:(JXCategoryCollectionView *)collectionView gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    if (collectionView.contentOffset.x <= 0) {
        if ([otherGestureRecognizer.delegate isKindOfClass:NSClassFromString(@"_FDFullscreenPopGestureRecognizerDelegate")]) {
            return YES;
        }
    }
    return NO;
}

若需要对指示器特殊处理 则对categoryview 自行写view

#pragma mark - 懒加载
- (JXCategoryTitleView *)categoryView{
    if (!_categoryView) {
        _categoryView = [[JXCategoryTitleView alloc] init];
        _categoryView.backgroundColor = [UIColor colorWithHexString:@"#F3F3F3"];
        _categoryView.layer.cornerRadius = 16;
        _categoryView.clipsToBounds = YES;
        _categoryView.delegate = self;
        _categoryView.titles = @[@"今天",@"7天",@"30天"];
        _categoryView.defaultSelectedIndex = 0;
        _categoryView.titleSelectedColor = [UIColor colorWithHexString:@"#161619"];
        _categoryView.titleColor = [UIColor colorWithHexString:@"#A3A3A3"];
        _categoryView.titleFont = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];

        JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
        backgroundView.size = CGSizeMake(52, 28);
        backgroundView.indicatorColor = UIColor.whiteColor;
        backgroundView.indicatorHeight = 28;
        backgroundView.indicatorWidth = 52;
        backgroundView.indicatorCornerRadius = 14;

        _categoryView.indicators = @[backgroundView];
        _categoryView.listContainer = self.listContainerView;
       
    }
    return _categoryView;
}

其他代码

- (void)viewDidLoad{
    [super viewDidLoad];
    [self setupViews];
}

- (void)setupViews{
    [self.view addSubview:self.categoryView];
    [self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(32);
        make.width.mas_equalTo(190);
        make.centerX.equalTo(self.view);
        make.top.equalTo(self.view).offset(23);
    }];
    
    [self.view addSubview:self.listContainerView];
    [self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.view);
        make.top.mas_equalTo(self.categoryView.mas_bottom).offset(28);
        make.bottom.mas_equalTo(self.view.mas_bottom);
    }];
}

- (NSArray<__kindof UIViewController *> *)controllers{
    return
    @[
        self.ADayVC,
        self.AWeakVC,
        self.AMonthVC,
    ];
}
- (JXCategoryListContainerView *)listContainerView
{
    if (!_listContainerView) {
        _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    }
    return _listContainerView;
}

- (LMContributionListToadayVC *)ADayVC{
    if (!_ADayVC) {
        _ADayVC = [[LMContributionListToadayVC alloc] init];
        _ADayVC.uid = self.uid;
        _ADayVC.liveid = self.liveid;
        _ADayVC.isAnchor = self.isAnchor;
    }
    return _ADayVC;
}

- (LMContributionListAWeakVC *)AWeakVC{
    if (!_AWeakVC) {
        _AWeakVC = [[LMContributionListAWeakVC alloc] init];
        _AWeakVC.uid = self.uid;
        _AWeakVC.liveid = self.liveid;
        _AWeakVC.isAnchor = self.isAnchor;
    }
    return _AWeakVC;
}

- (LMContributionListAMonthVC *)AMonthVC{
    if (!_AMonthVC) {
        _AMonthVC = [[LMContributionListAMonthVC alloc] init];
        _AMonthVC.uid = self.uid;
        _AMonthVC.liveid = self.liveid;
        _AMonthVC.isAnchor = self.isAnchor;
    }
    return _AMonthVC;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值