日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

复习知识点:UITableView和UICollectionView的常用属性

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 复习知识点: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

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的复习知识点:UITableView和UICollectionView的常用属性的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。