您好,我的 UICollectionView
有一个小问题。我目前没有设置任何间距设置,但我的单元格之间似乎有一个巨大的间隙,这非常烦人,如果有人能告诉我如何解决这个问题会有所帮助吗? id 假设它非常简单。
下面是我的 CollectionViewCells
发生的情况的示例:
自定义单元格.h
#import <UIKit/UIKit.h>
@interface CustomCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *IconImage;
@property (weak, nonatomic) IBOutlet UILabel *IconLabel;
@property (weak, nonatomic) IBOutlet UILabel *IconDescription;
@end
groupsviewcontroller.m
#import "GroupsViewController.h"
#import "CustomCell.h"
@interface GroupsViewController ()
{
NSArray *arrayOfImages;
NSArray *arrayOfDescriptions;
}
@end
@implementation GroupsViewController
{
NSString *reuseIdentifier;
}
- (void)viewDidLoad
{
[super viewDidLoad];
reuseIdentifier= @"SmallIcon";
[[self GroupsCollectionView]setDataSource:self];
[[self GroupsCollectionView]setDelegate:self];
arrayOfImages = [[NSArray alloc]initWithObjects:@"sin.png", nil];
arrayOfDescriptions = [[NSArray alloc]initWithObjects:@"Sin", nil];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [arrayOfDescriptions count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
[[cell IconImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
[[cell IconLabel]setText:[arrayOfDescriptions objectAtIndex:indexPath.item]];
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//Dispose of any resources that can be recreated.
}
- (IBAction)cellToggleAction:(id)sender {
//need to add toggle button to toggle between three different views
//small icon
//list view
//large icon
}
@end
最佳答案
1) 您应该检查您的 CustomCell
类,看看是否应用了任何大小限制。只需将单元格的背景设置为某种颜色,实际单元格大小就会突出显示。
2) 使用 (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
帮助您设置合适的单元格大小。此函数带有 UICollectionViewDelegateFlowLayout
:)
关于ios - UICollectionView 单元格留下巨大间隙所有设置设置为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35049465/