0

嗨,我有一个小问题,我的UICollectionView。我目前没有设置间距的任何设置,但我似乎有一个巨大的差距,我很担心,如果有人可以告诉我如何解决这个问题很有帮助的单元格之间的差距? id假设它非常简单。UICollectionView单元格留下巨大的空白所有设置设置为0

下面是发生了什么我CollectionViewCells一个例子:

enter image description here

定制cell.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 
+0

您是否通过编程创建了'UICollectionView'? – Breek

+0

是的,你想要的代码? –

+0

请别的,否则我们很难帮你:p – Breek

回答

1

1)您应检查你的CustomCell类,看看是否有任何si ze约束被应用。只需将单元格的背景设置为某种颜色,实际单元格大小将突出显示。

2)使用(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath来帮助自己设置正确的单元格大小。这个函数附带UICollectionViewDelegateFlowLayout :)

+0

你先生太棒了!这种简单的错过,但你几乎不会去寻找的东西,我只是有一个约束添加到我的自定义单元的界面生成器。再次感谢 –

+0

@LeeSugden欢迎您,如果它解决了您的问题,请将其标记为答案XP – Breek

相关问题