将两个单元格放在一个单元格

时间:2016-07-29 10:08:21

标签: xcode uicollectionview uicollectionviewcell

我想创建一个这样的布局:Collection View Layout

这是我的代码:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSMutableArray *mutable = [[NSMutableArray alloc] init];

    [mutable addObject:[NSValue valueWithCGSize:CGSizeMake(250, 399)]];
    [mutable addObject:[NSValue valueWithCGSize:CGSizeMake(124, 199)]];
    [mutable addObject:[NSValue valueWithCGSize:CGSizeMake(124, 199)]];
    [mutable addObject:[NSValue valueWithCGSize:CGSizeMake(375, 199)]];
    [mutable addObject:[NSValue valueWithCGSize:CGSizeMake(124, 199)]];
    [mutable addObject:[NSValue valueWithCGSize:CGSizeMake(124, 199)]];
    [mutable addObject:[NSValue valueWithCGSize:CGSizeMake(124, 199)]];

    array = [mutable copy];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return array.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    return cell;

}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return [array[indexPath.item] CGSizeValue];
}

但代码只显示了这一点:Current

但是集合视图只显示另一个单元格旁边的单元格。你能帮助我吗? 谢谢!

0 个答案:

没有答案