【发布时间】:2018-01-11 05:11:34
【问题描述】:
我已经向超级视图添加了一个 uicollectionView 并像这样决定单元格大小:
- (nonnull __kindof UICollectionViewCell *)collectionView:(nonnull UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath {
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
if(!cell){
cell = [[UICollectionViewCell alloc]init];
}
UIImageView *imageView = [[UIImageView alloc]initWithFrame:cell.bounds];
int r = arc4random_uniform(4);
NSString *imageName = [[NSString stringWithFormat:@"%d", r] stringByAppendingString:@".jpg"];
imageView.image = [UIImage imageNamed:imageName];
[cell addSubview:imageView];
cell.backgroundColor=[UIColor greenColor];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(180, 340);
}
- (NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 1500;
}
在设备上看起来像这样:
我希望两个图像之间的空间以及每行的填充和尾部相等。
我还想设置每行之间的间距。
我该怎么做?
【问题讨论】:
标签: ios objective-c uicollectionview