2013-11-25 124 views
1

http://postimg.org/image/6bws3catp/不同尺寸的collectionviewcells

如你我需要的东西,让我调整大小取决于包含文本的长度细胞的可能性在图像上看到。

我一直在尝试用UICollectionView做到这一点,但单元格的大小始终相同,如果我尝试更改大小并使用frame.size和位置参数来滚动,滚动会变得很疯狂。

也许UICollectionView是不是最好的选择...

非常感谢您

编辑:

因为你的答案我的细胞能够动态改变其大小,但利润率没有像我预期的那样行事。

细胞的利润率总是依赖于同一行

http://postimg.org/image/3scthf9rv/

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

我实现这个设置单元格之间我的保证金价值6分的最大的细胞,但也许这只是当你在一个垂直的集合视图中的每一行中的一个单元格..

再次感谢您对所有您的帮助工作

回答

0
  1. 您可以检查出https://github.com/bryceredd/RFQuiltLayout。看起来像 就像你可以使用这个...

  2. 你可以重写下面的方法并返回一个CGSize对象,它指定了你想要用于每个单元格的大小。使用这种方法,可以实际上有每个小区具有不同的尺寸:

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
    

实施例:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { 
    return CGSizeMake(100, 100); 
} 

你的视图控制器必须UICollectionViewDelegateFlowLayout的委托,以便使该方法叫做。所以不要忘了将代理声明添加到您的视图控制器的.h文件中,例如:

@interface MyViewController() <UICollectionViewDelegateFlowLayout> 
+0

非常感谢!你能帮我解决新的保证金问题吗? – Andoxko

+0

@AndoniMuruamendiaraz你的问题是什么? –

+0

我已经编辑了这个问题来解释它更好,还是创建一个新的问题更好?对不起,我是新来的:) – Andoxko

0

UICollectionView是正确的选择。您只需要自定义流布局属性。

阅读Customizing the Flow Layout Attributes

具体来说,你将需要实现Collection查看委托方法:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // In this method you can calculate the size of the string for each cell 
    UIFont *font = // font to create the text for each cell 
    NSString *string = // text string for each cell 
    CGSize size = [string sizeWithFont]; 
    return size; 
} 
+0

非常感谢您!!您的帮助非常有用。你能帮我保证金吗? – Andoxko