IrregularGridCollectionView處理不定寬度的標簽cell

IrregularGridCollectionView處理不定寬度的標簽cell

?

效果

?

源碼

https://github.com/YouXianMing/UI-Component-Collection 中的?IrregularGridCollectionView

//
//  IrregularGridCollectionView.h
//  IrregularGridCollectionView
//
//  Created by YouXianMing on 16/8/30.
//  Copyright ? 2016年 YouXianMing. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "IrregularGridCellDataAdapter.h"
#import "MaximumSpacingFlowLayout.h"
#import "CustomIrregularGridViewCell.h"
@class IrregularGridViewCellClassType;
@class IrregularGridCollectionView;@protocol IrregularGridCollectionViewDelegate <NSObject>@optional/***  IrregularGridCollectionView did selected event.**  @param collectionGridView CollectionGridView's object.*  @param cell               CustomCollectionGridViewCell type's cell.*  @param event              CustomCollectionGridViewCell's event.*/
- (void)irregularGridCollectionView:(IrregularGridCollectionView *)irregularGridCollectionView didSelectedCell:(CustomIrregularGridViewCell *)cell event:(id)event;@end@interface IrregularGridCollectionView : UIView/***  CollectionGridView's delegate.*/
@property (nonatomic, weak) id <IrregularGridCollectionViewDelegate> delegate;/***  CollectionView.*/
@property (nonatomic, strong, readonly) UICollectionView *collectionView;/***  Content edgeInsets, default is UIEdgeInsetsMake(5, 5, 5, 5).*/
@property (nonatomic) UIEdgeInsets contentEdgeInsets;/***  Horizontal item's gap, default is 5.f.*/
@property (nonatomic) CGFloat horizontalGap;/***  Vertical item's gap, default is 5.f.*/
@property (nonatomic) CGFloat verticalGap;/***  Item's height, default is 20.f.*/
@property (nonatomic) CGFloat gridHeight;/***  Register the cells.*/
@property (nonatomic, strong) NSArray <IrregularGridViewCellClassType *> *registerCells;/***  The cells data adapter.*/
@property (nonatomic, strong) NSMutableArray <IrregularGridCellDataAdapter *> *adapters;/***  To make the config effective.*/
- (void)makeTheConfigEffective;/***  Get the CollectionView's content size.*/
@property (nonatomic, readonly) CGSize contentSize;/***  Reset the view's size.*/
- (void)resetSize;#pragma mark - Constructor.+ (instancetype)irregularGridCollectionViewWithFrame:(CGRect)framedelegate:(id <IrregularGridCollectionViewDelegate>)delegateregisterCells:(NSArray <IrregularGridViewCellClassType *> *)registerCellscontentEdgeInsets:(UIEdgeInsets)edgeInsetsverticalGap:(CGFloat)verticalGaphorizontalGap:(CGFloat)horizontalGapgridHeight:(CGFloat)gridHeight;@end#pragma mark - CollectionGridViewCellClassType Class@interface IrregularGridViewCellClassType : NSObject@property (nonatomic)         Class      className;
@property (nonatomic, strong) NSString  *reuseIdentifier;@endNS_INLINE IrregularGridViewCellClassType *gridViewCellClassType(Class className, NSString  *reuseIdentifier) {IrregularGridViewCellClassType *type = [IrregularGridViewCellClassType new];type.className                        = className;type.reuseIdentifier                  = reuseIdentifier;return type;
}
//
//  IrregularGridCollectionView.m
//  IrregularGridCollectionView
//
//  Created by YouXianMing on 16/8/30.
//  Copyright ? 2016年 YouXianMing. All rights reserved.
//

#import "IrregularGridCollectionView.h"#pragma mark - IrregularGridCollectionView Class@interface IrregularGridCollectionView () <UICollectionViewDelegate, UICollectionViewDataSource, CustomIrregularGridViewCellDelegate>@property (nonatomic, strong) UICollectionView            *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout  *flowLayout;@end@implementation IrregularGridCollectionView#pragma mark - Init- (void)layoutSubviews {[super layoutSubviews];_collectionView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
}- (instancetype)initWithFrame:(CGRect)frame {if (self = [super initWithFrame:frame]) {self.contentEdgeInsets   = UIEdgeInsetsMake(5, 5, 5, 5);self.horizontalGap       = 5.f;self.verticalGap         = 5.f;self.gridHeight          = 20.f;// Init UICollectionViewFlowLayout.self.flowLayout = [[MaximumSpacingFlowLayout alloc] init];// Init UICollectionView.self.collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:self.flowLayout];self.collectionView.showsHorizontalScrollIndicator = NO;self.collectionView.showsVerticalScrollIndicator   = NO;self.collectionView.backgroundColor                = [UIColor clearColor];self.collectionView.delegate                       = self;self.collectionView.dataSource                     = self;[self addSubview:self.collectionView];}return self;
}- (void)makeTheConfigEffective {self.collectionView.contentInset        = self.contentEdgeInsets;self.flowLayout.minimumLineSpacing      = self.verticalGap;self.flowLayout.minimumInteritemSpacing = self.horizontalGap;
}#pragma mark - UICollectionView's delegate & data source.- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {return _adapters.count;
}- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {IrregularGridCellDataAdapter *adapter = _adapters[indexPath.row];adapter.indexPath                     = indexPath;CustomIrregularGridViewCell  *cell    = [collectionView dequeueReusableCellWithReuseIdentifier:adapter.cellReuseIdentifier forIndexPath:indexPath];cell.delegate                         = self;cell.dataAdapter                      = adapter;cell.data                             = adapter.data;cell.indexPath                        = indexPath;cell.collectionView                   = collectionView;cell.collectionGridView = self;[cell loadContent];return cell;
}- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {IrregularGridCellDataAdapter *adapter = _adapters[indexPath.row];return CGSizeMake(adapter.itemWidth, self.gridHeight);
}+ (instancetype)irregularGridCollectionViewWithFrame:(CGRect)framedelegate:(id <IrregularGridCollectionViewDelegate>)delegateregisterCells:(NSArray <IrregularGridViewCellClassType *> *)registerCellscontentEdgeInsets:(UIEdgeInsets)edgeInsetsverticalGap:(CGFloat)verticalGaphorizontalGap:(CGFloat)horizontalGapgridHeight:(CGFloat)gridHeight {IrregularGridCollectionView *irregularGridView = [[[self class] alloc] initWithFrame:frame];irregularGridView.delegate                     = delegate;irregularGridView.contentEdgeInsets            = edgeInsets;irregularGridView.verticalGap                  = verticalGap;irregularGridView.horizontalGap                = horizontalGap;irregularGridView.gridHeight                   = gridHeight;irregularGridView.registerCells                = registerCells;[irregularGridView makeTheConfigEffective];return irregularGridView;
}#pragma mark - CustomIrregularGridViewCellDelegate- (void)customIrregularGridViewCell:(CustomIrregularGridViewCell *)cell event:(id)event {if (self.delegate && [self.delegate respondsToSelector:@selector(irregularGridCollectionView:didSelectedCell:event:)]) {[self.delegate irregularGridCollectionView:self didSelectedCell:cell event:event];}
}#pragma mark - Setter & Getter- (void)setRegisterCells:(NSArray <IrregularGridViewCellClassType *> *)registerCells {_registerCells = registerCells;for (IrregularGridViewCellClassType *type in registerCells) {[self.collectionView registerClass:type.className forCellWithReuseIdentifier:type.reuseIdentifier];}
}- (CGSize)contentSize {CGSize size = [_flowLayout collectionViewContentSize];size.width  += self.contentEdgeInsets.left + self.contentEdgeInsets.right;size.height += self.contentEdgeInsets.top  + self.contentEdgeInsets.bottom;return size;
}- (void)resetSize {CGRect newFrame = self.frame;newFrame.size   = [self contentSize];self.frame      = newFrame;
}@end#pragma mark - IrregularGridViewCellClassType Class@implementation IrregularGridViewCellClassType@end

?

細節

?

轉載于:https://www.cnblogs.com/YouXianMing/p/6038248.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/270553.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/270553.shtml
英文地址,請注明出處:http://en.pswp.cn/news/270553.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

服務端負載均衡和客戶端負載均衡

服務端負載均衡 用戶在App訪問通過80端口請求nginx,ngin來實現負載均衡&#xff0c;分發請求 客戶端負載均衡 Eureka Server注冊中心集群部署&#xff0c;goods_services服務提供者啟動后向Eureka Server注冊中心進行服務注冊 App服務從Eureka Server發現服務 goods_servic…

java上傳和下載文件代碼_JavaWeb中上傳和下載文件實例代碼

一丶先引入上傳下載的lib二丶上傳的的servletpackage com.test.action;import java.io.file;import java.io.fileoutputstream;import java.io.ioexception;import java.io.inputstream;import java.io.outputstream;import java.util.list;import javax.servlet.servletexcept…

kafka java api 刪除_使用Java API創建(create),查看(describe),列舉(list),刪除(delete)Kafka主題(Topic)...

使用Kafka的同學都知道&#xff0c;我們每次創建Kafka主題(Topic)的時候可以指定分區數和副本數等信息&#xff0c;如果將這些屬性配置到server.properties文件中&#xff0c;以后調用Java API生成的主題將使用默認值&#xff0c;先改變需要使用命令bin/kafka-topics.sh --zook…

操作系統:Linux 環境變量配置的 6 種方法

目錄 Linux環境變量配置 Linux讀取環境變量 Linux環境變量配置方法一&#xff1a;export PATH Linux環境變量配置方法二&#xff1a;vim ~/.bashrc Linux環境變量配置方法三&#xff1a;vim ~/.bash_profile Linux環境變量配置方法四&#xff1a;vim /etc/bashrc Linux環境變量…

操作系統:Win10有哪些版本,看完你就知道了

目錄 一、win10家庭版 二、win10專業版 三、win10企業版 四、win10教育版 Win10有四個版本是我們最常見的&#xff1a;win10家庭版、win10專業版、win10企業版、win10教育版。 今天就主要說這4個比較經典的版本&#xff0c;一起來看看吧&#xff01; 一、win10家庭版 一般來說&…

mysql-5.5.8_MySQL5.5.8安裝

一、軟件包a) cmake-2.8.3.tar.gzb) mysql-5.5.8.tar.gz二、安裝步驟a) Tar zxvf cmake-2.8.3.tar.gzb) Cd cmake-2.8.3c) ./bootstrapd) Makee) Make installf) Tar zxvf mysql-5.5.8.tar.gzg) Cd mysql-5.5.8h) 配置參數cmake . -DCMAKE_INSTALL_PREFIX/usr/local/mysql5 \-D…

C# Web實時消息后臺服務器推送技術-GoEasy

越來越多的項目需要用到實時消息的推送與接收&#xff0c;怎樣用C#實現最方便呢&#xff1f;我這里推薦大家使用GoEasy, 它是一款第三方推送服務平臺&#xff0c;使用它的API可以輕松搞定實時推送&#xff01; 瀏覽器兼容性&#xff1a;GoEasy推送 支持websocket 和polling兩種…

硬件知識:打印機常見的故障及維護,值得收藏

一、打印時不出墨癥狀 打印機在聯機或自檢時&#xff0c;打印頭有動作&#xff0c;但打印不出墨。故障分析 這一情況發生&#xff0c;有多方面原因&#xff0c;可能包括噴頭故障&#xff0c;清潔單元故障&#xff0c;電鍍及電路板故障等&#xff0c;但在排除了噴頭故障后可以這…

mac下SecureCRT連接阿里云服務器最新教程

一.首先進入自己的阿里云管理控制臺 地址 https://ecs.console.aliyun.com/?spm5176.6660585.774526198.1.57c96bf8inrLvC#/home 二&#xff1a;輸入密碼 三&#xff1a;點擊密碼重置 四&#xff1a;打開SecureCRT 點擊加號 五&#xff1a;點擊continue 六&#xff1a;在Ho…

oralce之存儲過程

一&#xff1a;--循環向表emp中插入數據 1 declare 2 maxnumber number:10000;3 v_count number;4 begin5 v_count :0;6 FOR x IN 1..maxnumber7 LOOP8 v_count :v_count1;9 insert into emp (empno,ename,job,mgr,sal,comm) 10 valu…

java 日期calendar_java時間對象Date,Calendar和LocalDate/LocalDateTime

一、簡介Date&#xff1a;java.util.Date包&#xff0c;包含日期&#xff0c;時間&#xff0c;毫秒數。Calendar&#xff1a;java.util.Calendar包&#xff0c;abstract修飾&#xff0c;Date的很多方法已經過時遷移到了Calendar類上。LocalDate/LocalDateTime&#xff1a;java.…

IIS實現服務器反向代理用法介紹

今天給打擊分享IIS實現服務器反向代理用法&#xff0c;感興趣的可以學習一下&#xff01;場景&#xff1a;本地電腦啟動了兩個網站地址分別為&#xff1a;http://127.0.0.1:8081/Sitehttp://127.0.0.1:8082/Test要實現同一個端口訪問&#xff1a;http://127.0.0.1:8080/Sitehtt…

java if else過多_Spring Boot中如何干掉過多的if else!

需求這里虛擬一個業務需求&#xff0c;讓大家容易理解。假設有一個訂單系統&#xff0c;里面的一個功能是根據訂單的不同類型作出不同的處理。訂單實體&#xff1a;service接口&#xff1a;傳統實現根據訂單類型寫一堆的if else&#xff1a;策略模式實現利用策略模式&#xff0…

硬件知識:固態硬盤相關知識介紹

目錄 1、主控 2、固件算法 3、SSD的SATA接口與M.2接口 4、速度對比 今天就為大家全面科普一下固態硬盤的相關知識&#xff0c;讓大家購買時做到心中有數&#xff0c;按需選擇。 首先還是從SSD的結構來說起&#xff0c;SSD最基本的組成部件分為&#xff1a;主控芯片、閃存芯片、…

編碼實戰Web端聯系人的增刪改查

首先畫出分析圖 實現效果如圖 項目下的包如圖&#xff1a; 實體包 package com.contactSystem.entiey;public class Contact {private String Id;private String name;private String sex;private String age;private String phone;private String qq;private String email;pub…

選型java程序_Java程序員自動化指南

一、背景在Java web開發中&#xff0c;雖然Spring boot已經幫助我們簡化了很多工作&#xff0c;但項目中龐雜的業務仍然需要自己去編寫較多的 entity&#xff0c;vo&#xff0c;Mapper&#xff0c;Service&#xff0c; Controller 代碼等&#xff0c;那么我們有沒有什么辦法來簡…