復習知識點:UITableView和UICollectionView的常用屬性

UITableView

UICollectionView

 ?//UICollectionViewLayout

? ? //UICollectionViewLayout決定了UICollectionView如何顯示在界面上,Apple提供了一個最簡單的默認layout對象:UICollectionViewFlowLayout

? ? //Flow Layout是一個Cells的線性布局方案,并具有頁面和頁腳。其可定制的內容如下:

? ? //itemSize屬性

? ? //設定全局的Cell尺寸,如果想要單獨定義某個Cell的尺寸,可以使用下面方法:

? ? - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;

?? ?

? ? //minimumLineSpacing屬性

? ? //設定全局的行間距,如果想要設定指定區內Cell的最小行距,可以使用下面方法:

?? ?

? ? - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section;

?? ?

? ? //minimumInteritemSpacing屬性

? ? //設定全局的Cell間距,如果想要設定指定區內Cell的最小間距,可以使用下面方法:

? ? - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;

?

? ? //scrollDirection屬性

? ? //設定滾動方向,有UICollectionViewScrollDirectionVerticalUICollectionViewScrollDirectionHorizontal兩個值。

? ? //headerReferenceSize屬性與footerReferenceSize屬性

? ? //設定頁眉和頁腳的全局尺寸,需要注意的是,根據滾動方向不同,headerfooterwidthheight中只有一個會起作用。如果要單獨設置指定區內的頁面和頁腳尺寸,可以使用下面方法:

? ? - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;

?? ?

? ? - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;

?? ?

? ? //sectionInset屬性

? ? //設定全局的區內邊距,如果想要設定指定區的內邊距,可以使用下面方法:

? ? - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;

?? ?

? ? //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

?

? ? //UICollectionViewDataSource

? ? //返回collection view里區(section)的個數,如果沒有實現該方法,將默認返回1

? ? - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

?? ?

? ? //返回指定區(section)包含的數據源條目數(number of items),該方法必須實現:

? ? - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

?

? ? //返回某個indexPath對應的cell,該方法必須實現:

? ? - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

? ? {

? ? ? ? UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];

? ? ? ? if(indexPath.section==0)

? ? ? ? {

? ? ? ? ? ? cell.backgroundColor = [UIColor redColor];

? ? ? ? }

? ? ? ? else if(indexPath.section==1)

? ? ? ? {

? ? ? ? ? ? cell.backgroundColor = [UIColor greenColor];

? ? ? ? }

? ? ? ? return cell;

? ? }

?? ?

? ? //UICollectionViewCell結構上相對比較簡單,由下至上:

? ? //

? ? //首先是cell本身作為容器view

? ? //然后是一個大小自動適應整個cellbackgroundView,用作cell平時的背景

? ? //再其次是selectedBackgroundView,是cell被選中時的背景

? ? //最后是一個contentView,自定義內容應被加在這個view

? ? //collection view添加一個補充視圖(頁眉或頁腳)

? ? - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

?? ?

? ? //設定頁眉的尺寸

? ? - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section

?? ?

? ? //設定頁腳的尺寸

? ? - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section

?? ?

? ? //添加頁眉和頁腳以前需要注冊類和標識:

? ? - (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier

?

? ? //設定指定區內Cell的最小行距,也可以直接設置UICollectionViewFlowLayoutminimumLineSpacing屬性

? ? - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section

?? ?

? ? //設定指定區內Cell的最小間距,也可以直接設置UICollectionViewFlowLayoutminimumInteritemSpacing屬性

? ? - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section;

?? ?

? ? //UICollectionViewDelegate

? ? //當指定indexPath處的item被選擇時觸發

? ? - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

?

? ? //P.s. 當你刪除或添加元素時,一定要更新numberOfItemsInSection的返回情況。

? ? //當指定indexPath處的item被取消選擇時觸發,僅在允許多選時被調用

? ? - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath

?

? ? //下面是三個和高亮有關的方法:

? ? //事件的處理順序如下:

? ? //

? ? //手指按下

? ? //shouldHighlightItemAtIndexPath (如果返回YES則向下執行,否則執行到這里為止)

? ? //didHighlightItemAtIndexPath (高亮)

? ? //手指松開

? ? //didUnhighlightItemAtIndexPath (取消高亮)

? ? //shouldSelectItemAtIndexPath (如果返回YES則向下執行,否則執行到這里為止)

? ? //didSelectItemAtIndexPath (執行選擇事件)

? ? //如果只是簡單實現點擊后cell改變顯示狀態,只需要在cellForItemAtIndexPath方法里返回cell時,指定cellselectedBackgroundView

? ? - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath

? ? - (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath

? ? - (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath

?

轉載于:https://www.cnblogs.com/crazygeek/p/5537898.html

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

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

相關文章

ASP.NET+MVC+使用+Log4net+記錄日志筆記

前言:記錄系統中的日志,是一個好的項目產品必備的一個環節。每一個產品最終的目的都是要交予客戶使用,因為程序員代碼的開發水平參差不齊,Bug就成為了項目運維成本最大的因素之一。如何降低項目運維的成本呢,最重要的是…

git分支feature和hotfix分支

master: 主分支,主要用來版本發布。develop:日常開發分支,該分支正常保存了開發的最新代碼。feature:具體的功能開發分支,只與 develop 分支交互。release:release 分支可以認為是 master 分支的未測試版。…

linux查看鏡像的詳細信息,docker inspect命令查看鏡像詳細信息

# docker inspect ubuntu:18.04 // 查看鏡像的詳細信息[{"Id": "sha256:d131e0fa2585a7efbfb187f70d648aa50e251d9d3b7031edf4730ca6154e221e","RepoTags": ["ubuntu:18.04"],"RepoDigests": ["ubuntusha256:d26d529da…

Golang使用pkg-config自動獲取頭文件和鏈接庫的方法

為了能夠重用已有的C語言庫,我們在使用Golang開發項目或系統的時候難免會遇到Go和C語言混合編程,這時很多人都會選擇使用cgo。 話說cgo這個東西可算得上是讓人又愛又恨,好處在于它可以讓你快速重用已有的C語言庫,無需再用Golang重…

數據庫:SQLServer中with as 用法筆記

一、with as 概念介紹with as 也叫做子查詢部分(subquery factoring),可以定義一個SQL段落,該SQL段落可以被整個SQL語句所用到類似于臨時表的作用。with as 可以提高你的SQL語句的可讀性,也有可以用在在UNION ALL的不同…

單詞

Screenshot 屏幕截圖,截圖 Dashboard n. 儀表盤 subscribe vt. 簽署;贊成;捐助 vi. 訂閱;捐款;認購;贊成;簽署 performance n. 性能;績效;表演;執行 optimization …

數據庫優化:SqlServer的with(nolock)關鍵字的用法介紹

一、with(nolock)的介紹數據庫寫查詢語句的時候,為了提升查詢性能,往往會在查詢的表后面加一個nolock,或者是with(nolock),其目的就是查詢的時候是不鎖定表,從而提高查詢速度的目的。但如果同一時間有多個用戶訪問同一資源的時候,如果并發用戶對該資源做了修改。則會…

對layoutInflater的理解

參考該博客:http://www.cnblogs.com/top5/archive/2012/05/04/2482328.html LayoutInflater是一個抽象類,通過調用其實例方法inflate(),將res/layout下的xml布局文件進行實例化,不同于findvirebyid()是找布局文件下的控件進行實例…

linux /root /etc,Linux知識:/root/.bashrc與/etc/profile的異同

要搞清bashrc與profile的區別,首先要弄明白什么是交互式shell和非交互式shell,什么是login shell 和non-login shell。交互式模式就是shell等待你的輸入,并且執行你提交的命令。這種模式被稱作交互式是因為shell與用戶進行交互。這種模式也是…

java多線程售票例子

代碼如下: public class Ticket1 implements Runnable {private int tickets 100;Overridepublic void run() {while (tickets > 0) {synchronized (Ticket.class) {if (tickets > 0) {tickets--;System.out.println(Thread.currentThread().getName() "正在賣票&…

推薦一款免費國產遠程辦公神器ToDesk,TeamViewer完美替代品

對于從事IT行業的人員來說,遠程軟件基本上是必備的軟件。之前使用用TeamViewer遠程辦公軟件,它的穩定性、延遲低、功能齊全很受廣大開發者的歡迎。唯一美中不足的是它是一款商業軟件。費用比較高。到現在基本上所有破解工具都無效了。所以不得不放棄這款…

[iOS] photoKit獲取所有照片

代碼: - (NSMutableArray *)getAllPhoto{NSMutableArray *arr [NSMutableArray array];// 所有智能相冊PHFetchResult *smartAlbums [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular optio…

用python寫linux中的ls,Python實現Linux環境下的ls命令

在Linux下使用ls命令結合正則表達式,能夠高效地進行文件搜索,并通過參數操作文件,于是就想用Python實現這個功能以便在Windows上使用import osimport reimport syspath os.getcwd()substr raw_input(The sub-string of the file (Support f…

蘋果臺式電腦怎么開機_龍華蘋果電腦回收公司,臺式電腦回收公司電話

龍華蘋果電腦回收公司,臺式電腦回收公司電話oDYIHx 通常液晶顯示器有VGA和DVI兩種種接口,其中VGA接口在長時間顯示后悔出現畫面模糊情況,需要校正才能恢復,然而DVi接口傳輸就比較穩定,它屬于全數字無損傳輸信號,在長…

AtomicInteger使用非阻塞算法,實現并發控制多線程實現售票

代碼如下: public class TicketDemo implements Runnable {private static volatile AtomicInteger ticketSum new AtomicInteger(20);private static int finalTotal 0;Overridepublic void run() {int count;while ((count ticketSum.decrementAndGet()) > 0) {System.…

數據庫:SQLServer 實現行轉列、列轉行用法筆記

在許多的互聯網項目當中,報表開發是整個項目當中很重要的一個功能模塊。其中會有一些比較復雜的報表統計需要行轉列或者列轉行的需求。今天給大家簡單介紹一下在SQLServer當中如何使用PIVOT、UNPIVOT內置函數實現數據報表的行轉列、列轉行。有需要的朋友可以一起學習…

硬件知識:串口通訊的起始、數據、停止位是怎么分配的?

串口是串行接口(serial port)的簡稱,也稱為串行通信接口或COM接口。串口通信是指采用串行通信協議(serial communication)在一條信號線上將數據一個比特一個比特地逐位進行傳輸的通信模式。串口按電氣標準及協議來劃分…

ES5 getter setter

最近在學習vuejs,了解到內部實現使用到了es5的Getters和Setters。之前看高程的時候,沒有重視這塊,今天查看一下文檔,了解了他們的作用,再次記錄一下,可供以后查看和共享。 定義Getters和Setters&#xff1a…

python 調用bat失敗_要想順利通過Python面試,你最起碼需要達到白銀段位!

近幾年 Python 非常熱門,在學術界和產業界的使用率顯著提高。目前學習Python的人數日益增多,Python在近3年的編程語言受歡迎度中一直處于榜首。今天我們就來講講在產業界,需要具備哪些能力才能獲得一個滿意的 Python 相關崗位 Offer。Python基…

多線程售票demo,用ReentrantLock實現

代碼: public class TicketReentLockDemo implements Runnable {private int ticketTotal 100;private Lock lock new ReentrantLock();Overridepublic void run() {while (ticketTotal > 0) {try {lock.lock();if (ticketTotal > 0) {try {TimeUnit.MILLISECONDS.sle…