表格里的網(wǎng)格

先正常寫表格UITableView,下面的是設(shè)置表格分組的樣式,(不分組就把表格樣式的改成indexPath.row就行了)

在表格內(nèi)容里寫:(就是創(chuàng)建網(wǎng)格必須的流水布局和設(shè)置網(wǎng)格里圖片位置的東西)

??????? tbv.rowHeight = 360;

? ? ? ? //創(chuàng)建流水布局? 確定單元格的位置

? ? ? ? UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];

? ? ? ? //設(shè)置單元格大小

? ? ? ? flow.itemSize = CGSizeMake((self.view.frame.size.width - 4)/4, (360 - 3)/3);

? ? ? ? //設(shè)置分區(qū)間距? (上邊距,左,下,右)

? ? ? ? flow.sectionInset = UIEdgeInsetsMake(30, 80, 10, 80);

? ? ? ? //設(shè)置最小的行間距

? ? ? ? flow.minimumLineSpacing = 0.5;

? ? ? ? //設(shè)置最小的列間距

? ? ? ? flow.minimumInteritemSpacing = 1;

? ? ? ? //創(chuàng)建網(wǎng)格視圖

? ? ? ? collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 360) collectionViewLayout:flow];


? ? ? ? collect.delegate = self;

? ? ? ? collect.dataSource = self;

? ? ? ? collect.backgroundColor = [UIColor whiteColor];


? ? ? ? //注冊(cè)單元格

? ? ? ? [collect registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuse];


? ? ? ? [cell addSubview:collect];



然后就是正常寫網(wǎng)格里的東西了:

記得最上面@end下邊寫:


NSString *reuse = @"cell";


//這是設(shè)置網(wǎng)格里共有幾個(gè)圖的

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

? ? return 4;

}

//這是設(shè)置網(wǎng)格里cell內(nèi)容的(主要添加圖片的)注意是:(UICollectionView )


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

? ? UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuse forIndexPath:indexPath];

? ? //設(shè)置 cell 內(nèi)容

? ? cell.backgroundColor = [UIColor darkGrayColor];

? ? UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, (self.view.frame.size.width - 4)/4, (360 - 3)/3)];

? ? imgV.image = [UIImage imageNamed:@"勾選的副本"];

? ? [cell addSubview: imgV];

? ? //返回cell

? ? return cell;

}

最后是效果圖:

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容