ios - UICollectionView 单元格留下巨大间隙所有设置设置为 0

标签 ios objective-c xcode uicollectionview uicollectionviewcell

您好,我的 UICollectionView 有一个小问题。我目前没有设置任何间距设置,但我的单元格之间似乎有一个巨大的间隙,这非常烦人,如果有人能告诉我如何解决这个问题会有所帮助吗? id 假设它非常简单。

下面是我的 CollectionViewCells 发生的情况的示例:

enter image description here

自定义单元格.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/

相关文章:

ios - 可以使用 AudioUnit (CoreAudio) 将音频编码为 AAC 或 MP3 吗?

iphone - NSURLConnection、基本身份验证和 Cookie 问题

swift - 服务扩展和内容扩展的供应配置文件

ios - 使用 Swift 将相机焦点设置在点击点上

iphone - 仅从目录获取图像文件

ios - 编译构建失败时出现 xcode 错误

ios - 使用 swfit 通过 UIWebview 登录 facebook 显示空白

ios - iOS应用程式其他内容下载

ios - 具有动态 subview swift 的 UITableViewCell 高度

ios - 如何加载具有透明背景颜色的 UIViewController?