JXCategoryTitleView的使用

el/2023/9/24 21:00:07

最近写项目,遇到了一个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;
}


http://www.ngui.cc/el/3419335.html

相关文章

基本编程能力练习

一、首先下载Java的编译环境并安装 JDK下载地址&#xff1a;https://www.oracle.com/java/technologies/javase-jdk15-downloads.html 选择适合自己系统的版本进行安装 这里我选择的是jdk-15_windows-x64_bin.exe 下载完成后直接运行安装&#xff0c;安装位置选择默认的C盘&am…

基本任务1.1Java语言基础

一、任务要求 完成基本数据类型的使用。完成基本运算符和表达式的使用。完成基本控制语句&#xff1a;判断、分支、循环等语句的使用。完成数组的使用。所有源代码必须加入行一级注释。 二、任务的理解 本次任务是让我们对Java编程中所遇到的基础知识进行学习和掌握&#xf…

基本任务1.1Java语言基础(任务挑战)

任务挑战&#xff1a; 1.编制一个Java application应用程序&#xff0c;把数组中已知的10个数字由小到大排序后输出。 编程前思考&#xff1a; 完成数组排序的方法有多种&#xff0c;其中有调用Arrays类中的sort方法直接对数组进行由小到大的排序&#xff0c;还可以采用冒泡排序…

基本任务1.2Java面向对象程序

一、任务要求 完成一个Java application应用程序&#xff0c;描述一个人类。要求如下&#xff1a;要求此人类必须包含有人的姓名、性别、出生日期等基本属性&#xff08;变量&#xff09;。要求此人类描述吃饭的方法&#xff08;函数&#xff09;和描述睡觉的方法&#xff08;…

基本任务1.3Java API

完成一个 java application应用程序&#xff0c;可以接收用户通过键盘输入的文本&#xff0c;并输出此段文本字符的个数。 代码&#xff1a; package task; //包名 import java.util.Scanner; //导入Scanner类 public class JavaAPI { //创建类public static void…

Tensorflow的安装与配置

Tensorflow的安装与配置 经过多次的安装失败&#xff0c;找寻原因&#xff0c;最终安装成功。 1、基于之前安装的anaconda的基础上进行tensorflow的安装&#xff0c;首先通过按windows键和R键弹出运行框&#xff0c;输入CMD回车&#xff0c;进入cmd命令窗口&#xff0c;先查询…

基本任务1.4java异常捕捉机制

Java异常捕捉机制 任务要求&#xff1a; 一、完成一个 java application应用程序&#xff0c;完成ca/b 的计算并输出c的结果&#xff0c;可以为a和b在程序中赋初值、或者接收用户通过键盘输入a和b的数值文本后转换为数字等&#xff0c;在程序要求当 b 为0时c的计算结果正确。…

基本任务4.2WEB服务

任务要求&#xff1a; 一、学习Tomcat服务器的安装和配置&#xff0c;要求把其WEB根路径从默认值改为自定义的路径&#xff0c;要求把其WEB默认服务端口改为80。二、把基本任务4.1基本任务和挑战任务所完成的静态WEB页面放到WEB服务器根路径下&#xff0c;启动WEB服务器&#…

MySQL Server 5.5安装

MySQL数据库安装 一、下载安装包 网站&#xff1a;https://dev.mysql.com/downloads/installer/ 然后点击下载&#xff0c;也可以下载老版本。 二、安装 MySQL Server 5.5安装步骤如下&#xff1a;&#xff08;其余版本安装步骤略有不同&#xff09; 三、测试 在命令…

语音信号线性预测分析

语音信号线性预测分析 基本思想&#xff1a;一个语音取样的现在值可以用若干个语音取样过去值的加权线性组合来逼近&#xff08;最小均方误差&#xff09;。线性预测最重要的优势在于它可以较为精确地估计语音的参数&#xff0c;而这些极少的参数可以正确地表现语音信号的时域…