gpt4 book ai didi

iphone - iOS - 当设置为 0 时 UICollectionView 间距仍然存在 - 如何设置单元格之间没有间距

转载 作者:IT王子 更新时间:2023-10-29 08:13:10 26 4
gpt4 key购买 nike

我有一个简单的 UICollectionView,我在 InterfaceBuilder 中设置了 0 间距,但是当我用单元格填充 Collection View 时,仍然有一些间距。除了将其设置为 0 间距之外,为了实际看到间距为 0 的 collectionview 单元格,我还需要做一些特殊且不是很明显的事情吗?谢谢。

编辑*一些代码:

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

UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

cell.backgroundColor = [UIColor clearColor];

UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(2, 2, cell.frame.size.width -4, cell.frame.size.height -4)];
lbl.backgroundColor = [UIColor clearColor];
lbl.font = [UIFont boldSystemFontOfSize:20];
lbl.text = [NSString stringWithFormat:@"$%0.0f", [[amountsArray objectAtIndex:indexPath.row] floatValue]];
lbl.textAlignment = NSTextAlignmentCenter;
lbl.layer.borderWidth = 1;

[cell addSubview:lbl];
[lbl release];

return cell;
}

enter image description here

最佳答案

针对您的查询的简单解决方案。将此添加到您的 viewController 的 .m 文件中:

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
ProductDetailViewController *HomeVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ProductDetailView"];
HomeVC.title = @"DemoProject";
[self.navigationController pushViewController:HomeVC animated:YES];
}

- (UIEdgeInsets)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(0, 0, 0, 0); // top, left, bottom, right
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {

return 0.0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 0.0;
}

关于iphone - iOS - 当设置为 0 时 UICollectionView 间距仍然存在 - 如何设置单元格之间没有间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19250284/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com