JXCategoryView的使用總結

来源:https://www.cnblogs.com/reyzhang/p/18267183
-Advertisement-
Play Games

一、初始化 -(JXCategoryTitleView *)categoryView{ if (!_categoryView) { _categoryView = [[JXCategoryTitleView alloc] init]; _categoryView.delegate = self; _ ...


一、初始化

-(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;
}

二、關聯listContainerView

  • listContainerView 創建
-(JXCategoryListContainerView *)listContainerView{
    if (!_listContainerView) {
        _listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
        _listContainerView.scrollView.scrollEnabled = YES;
    }
    return _listContainerView;
}
  • 與categoryView 建立關聯
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屬性賦值, 如果需要動態顯示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

本文來自博客園,作者:reyzhang,轉載請註明原文鏈接:https://www.cnblogs.com/reyzhang/p/18267183


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1.前言 因為小程式是由js代碼編寫的,我js學得不是特別的好,所以,剛開始以為js跟java一行,一行一行的執行,後面才發現,完全不是,所以有時候,我們在獲取用戶信息和openId的時候,要向後臺發送請求,所以有時有可能請求還沒有返回數據,小程式這邊已經賦值了,只能得到一個undifine,很桑心 ...
  • UINavigationController 是 iOS 中用於管理視圖控制器層次結構的一個重要組件,通常用於實現基於堆棧的導航。它提供了一種用戶界面,允許用戶在視圖控制器之間進行層次化的導航,例如從列表視圖到詳細視圖。 UINavigationController 的主要功能 管理視圖控制器堆棧: ...
  • UITabBarController 是 iOS 中用於管理和顯示選項卡界面的一個視圖控制器。它允許用戶在多個視圖控制器之間進行切換,每個視圖控制器對應一個選項卡。 主要功能 管理多個視圖控制器: UITabBarController 管理一個視圖控制器數組,每個視圖控制器對應一個選項卡。 顯示選項 ...
  • 在MVC模型中,V指view,負責用戶界面的顯示、處理用戶輸入,並將輸入傳遞給控制器。C是指ViewController,充當模型和視圖之間的中介。控制器接收用戶輸入,處理用戶請求,並將結果傳遞給視圖以更新顯示。本文詳細介紹在iOS開發中UIView與UIViewController的生命周期。 U ...
  • 目錄前言一、Jetpack Compose 中處理嵌套滾動的思想二、Modifier.nestedScroll2.1 NestedScrollConnection2.2 NestedScrollDispatcher三、實操講解3.1 父組件消費子組件給過來的事件——NestedScrollConne ...
  • 目錄一、點按手勢1.1 Modifier.clickable1.2 Modifier.combinedClickable二、滾動手勢2.1 滾動修飾符 Modifier.verticalScorll / Modifier.horizontalScorll2.2 可滾動修飾符 Modifier.scr ...
  • OpenGrok是一個源碼搜索及交叉引用查詢引擎,OpenGrok的引入可以幫助我們更好地在浩如煙海的源碼里找到自己需要的那坨代碼。 ...
  • 影響護眼的因素 藍光 目前手機大多已經實現硬體低藍光,而且藍光也可以通過護眼模式輕易剋服。 偏振光 偏振光指振動方向與傳播方向不對稱的光,主要分為圓偏振光與線偏振光兩種。 線偏振光測試方法為:透過偏振片看屏幕,旋轉偏振片,若存在某個角度屏幕發出的光線無法透過偏振片,則是線偏振光。一些墨鏡鏡片、相機的 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...