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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

UICollectionView的使用方法

發布時間:2023/11/27 生活经验 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UICollectionView的使用方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、遵守協議

<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

2、創建

?UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
??? layout.minimumInteritemSpacing = 10;? //最小item之間的間距
??? layout.minimumLineSpacing = 10;//最小行間距
??? collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-64-49) collectionViewLayout:layout];
??? collectionView.delegate = self;
??? collectionView.dataSource = self;

//重要

1>、如果是用代碼自定義的cell要用下面的方法注冊

?[collectionView registerClass:[PicCollectionViewCell class] forCellWithReuseIdentifier:@"cc"];

2>、如果是用xib定義的cell要用

[collectionView registerNib:[UINib nibWithNibName:@"PicCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"cc"];

3、返回item的個數

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
??? return dataSourse.count;
}

4、cell復用

xib和代碼都用下面方法

PicCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cc" forIndexPath:indexPath];

5、重要協議方法

1>返回item的大小,系統自動根據item的大小來設定每行顯示的item個數(可以用layout.size方法)

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
??? CGSize? size = CGSizeMake(90, 80);
??? return size;
}

2>//返回這個UICollectionView是否可以被選擇?

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

{? return?YES;??

}

轉載于:https://www.cnblogs.com/huoxingdeguoguo/p/4630948.html

總結

以上是生活随笔為你收集整理的UICollectionView的使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。

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