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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

objective-C CollectionView 加深(添加注册头部View)

發布時間:2025/3/8 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 objective-C CollectionView 加深(添加注册头部View) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

#pragma?marc?添加Collection -(void)addConllectionView{//collection的布局方案UICollectionViewFlowLayout?*collectionViewLayout=[[UICollectionViewFlowLayout?alloc]init];//設置位置大小以及布局方案_myCollectionView=[[UICollectionView?alloc]initWithFrame:CM(0,?0,?VIEW_WIDTH,VIEW_HEIGHT-64-48)?collectionViewLayout:collectionViewLayout];//CollectionView的背景顏色_myCollectionView.backgroundColor=[UIColor?whiteColor];[self?addSubview:_myCollectionView];//設置代理_myCollectionView.delegate=self;_myCollectionView.dataSource=self;//注冊Cell?以及選擇控制的類[_myCollectionView?registerClass:[ExhibitionCollectionViewCell?class]?forCellWithReuseIdentifier:@"cell"];//注冊Head以及Food?以及選擇控制的類[_myCollectionView?registerClass:[UICollectionReusableView?class]?forSupplementaryViewOfKind:UICollectionElementKindSectionHeader?withReuseIdentifier:@"Head"];} #pragma?mark?設置Cell -(UICollectionViewCell?*)collectionView:(UICollectionView?*)collectionView?cellForItemAtIndexPath:(NSIndexPath?*)indexPath{ExhibitionCollectionViewCell?*cell=[_myCollectionView?dequeueReusableCellWithReuseIdentifier:@"cell"?forIndexPath:indexPath];cell.backgroundColor=[UIColor?whiteColor];cell.imageView.image=[UIImage?imageNamed:@"商品"];return?cell; } #pragma?mark?設置頭部以及尾部 -?(UICollectionReusableView?*)collectionView:(UICollectionView?*)collectionView?viewForSupplementaryElementOfKind:(NSString?*)kind?atIndexPath:(NSIndexPath?*)indexPath {if?([kind?isEqualToString:UICollectionElementKindSectionHeader])?{//和判斷復用一樣UICollectionReusableView?*?head?=?[collectionView?dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader?withReuseIdentifier:@"Head"?forIndexPath:indexPath];//添加輪播圖[head?addSubview:_carouselFigureView];return?head;}return?nil;} #pragma?mark?設置Cell返回數量 -(NSInteger)collectionView:(UICollectionView?*)collectionView?numberOfItemsInSection:(NSInteger)section{return?20; } #pragma?mark?定義展示的組數 -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView?*)collectionView {return?1; }#pragma?mark?設置cell的大小 -?(CGSize)collectionView:(UICollectionView?*)collectionView?layout:(UICollectionViewLayout*)collectionViewLayout?sizeForItemAtIndexPath:(NSIndexPath?*)indexPath {return?CGSizeMake(VIEW_WIDTH/3.55f,?VIEW_HEIGHT/3.550f);}#pragma?mark?設置每個section中不同的行之間的行間距 -?(CGFloat)collectionView:(UICollectionView?*)collectionView?layout:(UICollectionViewLayout*)collectionViewLayout?minimumLineSpacingForSectionAtIndex:(NSInteger)section {return?20; } #pragma?mark?設置每個section中不同的列之間的間距 -?(CGFloat)collectionView:(UICollectionView?*)collectionView?layout:(UICollectionViewLayout*)collectionViewLayout?minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {return?10; } #pragma?mark?設置每個Cell的內邊距 -(UIEdgeInsets)collectionView:(UICollectionView?*)collectionView?layout:(UICollectionViewLayout?*)collectionViewLayout?insetForSectionAtIndex:(NSInteger)section {return?UIEdgeInsetsMake(0,?0,?10,?0);//分別為上、左、下、右 } #pragma?mark?點擊事件 -?(void)collectionView:(UICollectionView?*)collectionView?didSelectItemAtIndexPath:(NSIndexPath?*)indexPath{CommodityDisplayControllerView?*?CDVC=[[CommodityDisplayControllerView?alloc]init];[[self?getController]?presentViewController:CDVC?animated:YES?completion:nil];NSLog(@"%ld",indexPath.row); }#pragma?mark?返回頭headerView的大小 -(CGSize)collectionView:(UICollectionView?*)collectionView?layout:(UICollectionViewLayout?*)collectionViewLayout?referenceSizeForHeaderInSection:(NSInteger)section{CGSize?size={VIEW_WIDTH,IMG_EXHIBITION_HEIGHT};return?size; }


轉載于:https://my.oschina.net/u/2483781/blog/645035

總結

以上是生活随笔為你收集整理的objective-C CollectionView 加深(添加注册头部View)的全部內容,希望文章能夠幫你解決所遇到的問題。

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