当前位置:   article > 正文

JXCategoryTitleView的使用

jxcategorytitleview

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

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

必写属性

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

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

  1. #pragma mark - JXCategoryListContentViewDelegate
  2. - (UIView *)listView{
  3. return self.view;
  4. }
  1. #pragma mark - JXCategoryListContainerViewDelegate
  2. - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index{
  3. __kindof UIViewController *vc = self.controllers[index];
  4. return vc;
  5. }
  6. - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
  7. return self.controllers.count;
  8. }
  1. #pragma mark - JXCategoryViewDelegate
  2. // 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
  3. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  4. //侧滑手势处理
  5. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  6. }
  7. - (BOOL)categoryCollectionView:(JXCategoryCollectionView *)collectionView gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  8. if (collectionView.contentOffset.x <= 0) {
  9. if ([otherGestureRecognizer.delegate isKindOfClass:NSClassFromString(@"_FDFullscreenPopGestureRecognizerDelegate")]) {
  10. return YES;
  11. }
  12. }
  13. return NO;
  14. }

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

  1. #pragma mark - 懒加载
  2. - (JXCategoryTitleView *)categoryView{
  3. if (!_categoryView) {
  4. _categoryView = [[JXCategoryTitleView alloc] init];
  5. _categoryView.backgroundColor = [UIColor colorWithHexString:@"#F3F3F3"];
  6. _categoryView.layer.cornerRadius = 16;
  7. _categoryView.clipsToBounds = YES;
  8. _categoryView.delegate = self;
  9. _categoryView.titles = @[@"今天",@"7天",@"30天"];
  10. _categoryView.defaultSelectedIndex = 0;
  11. _categoryView.titleSelectedColor = [UIColor colorWithHexString:@"#161619"];
  12. _categoryView.titleColor = [UIColor colorWithHexString:@"#A3A3A3"];
  13. _categoryView.titleFont = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
  14. JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
  15. backgroundView.size = CGSizeMake(52, 28);
  16. backgroundView.indicatorColor = UIColor.whiteColor;
  17. backgroundView.indicatorHeight = 28;
  18. backgroundView.indicatorWidth = 52;
  19. backgroundView.indicatorCornerRadius = 14;
  20. _categoryView.indicators = @[backgroundView];
  21. _categoryView.listContainer = self.listContainerView;
  22. }
  23. return _categoryView;
  24. }

其他代码

  1. - (void)viewDidLoad{
  2. [super viewDidLoad];
  3. [self setupViews];
  4. }
  5. - (void)setupViews{
  6. [self.view addSubview:self.categoryView];
  7. [self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
  8. make.height.mas_equalTo(32);
  9. make.width.mas_equalTo(190);
  10. make.centerX.equalTo(self.view);
  11. make.top.equalTo(self.view).offset(23);
  12. }];
  13. [self.view addSubview:self.listContainerView];
  14. [self.listContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
  15. make.left.right.mas_equalTo(self.view);
  16. make.top.mas_equalTo(self.categoryView.mas_bottom).offset(28);
  17. make.bottom.mas_equalTo(self.view.mas_bottom);
  18. }];
  19. }
  20. - (NSArray<__kindof UIViewController *> *)controllers{
  21. return
  22. @[
  23. self.ADayVC,
  24. self.AWeakVC,
  25. self.AMonthVC,
  26. ];
  27. }
  28. - (JXCategoryListContainerView *)listContainerView
  29. {
  30. if (!_listContainerView) {
  31. _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
  32. }
  33. return _listContainerView;
  34. }
  35. - (LMContributionListToadayVC *)ADayVC{
  36. if (!_ADayVC) {
  37. _ADayVC = [[LMContributionListToadayVC alloc] init];
  38. _ADayVC.uid = self.uid;
  39. _ADayVC.liveid = self.liveid;
  40. _ADayVC.isAnchor = self.isAnchor;
  41. }
  42. return _ADayVC;
  43. }
  44. - (LMContributionListAWeakVC *)AWeakVC{
  45. if (!_AWeakVC) {
  46. _AWeakVC = [[LMContributionListAWeakVC alloc] init];
  47. _AWeakVC.uid = self.uid;
  48. _AWeakVC.liveid = self.liveid;
  49. _AWeakVC.isAnchor = self.isAnchor;
  50. }
  51. return _AWeakVC;
  52. }
  53. - (LMContributionListAMonthVC *)AMonthVC{
  54. if (!_AMonthVC) {
  55. _AMonthVC = [[LMContributionListAMonthVC alloc] init];
  56. _AMonthVC.uid = self.uid;
  57. _AMonthVC.liveid = self.liveid;
  58. _AMonthVC.isAnchor = self.isAnchor;
  59. }
  60. return _AMonthVC;
  61. }

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号