我想放一个水平显示拇指的UICollectionView控件(只有一行拇指).由于某种原因,UICollectionView将拇指向下推44像素,因此"0"高度实际上是"44".我假设它可能会添加这个空间来考虑导航栏高度(我只是假设).由于我的UICollectionView仅在屏幕的一部分上,我不想要这个边距.有没有办法删除它?
我有一个CollectionViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// assign layout (subclassed below)
self.collectionView.collectionViewLayout = [[CustomCollectionLayout alloc] init];
}
// data source is working, here's what matters:
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
ThumbCell *cell = (ThumbCell *)[cv dequeueReusableCellWithReuseIdentifier:@"ThumbCell" forIndexPath:indexPath];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我还有一个UICollectionViewLayout子类:CustomCollectionLayout.m
#pragma mark - Overriden methods
- (CGSize)collectionViewContentSize
{
return CGSizeMake(320, 480);
}
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect
{
return [[super layoutAttributesForElementsInRect:rect] mutableCopy];
}
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
// configure CellAttributes
cellAttributes = [super layoutAttributesForItemAtIndexPath:indexPath];
// random position
int …Run Code Online (Sandbox Code Playgroud)