2

2 種類の UICollectionViewCells を持つ UICollectionView があります。各タイプのセルの表示を促すタブがあり、一度に表示できるのは 1 つのタイプのセルだけです。

何らかの理由で、1 種類のセルは UICollectionView で左に配置されますが、もう 1 つのセルは中央に水平に配置されます。両方のタイプのセルを左揃えにしたいと思います。

エッジ インセットは次のとおりです。

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10,10,10,10);
}

どんな助けでも大歓迎です。

4

1 に答える 1

2

セルはサイズによってレイアウトが異なるため、セル タイプごとに異なるインセットを使用する必要があります。次のように実行できるはずだと思います:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:section];
    if ([cell isKindOfClass:[MyClass1 class]]){
        return UIEdgeInsetsMake(10,10,10,10);
    }else{
        return UIEdgeInsetsMake(20,10,10,10);
}

MyClass1 を正しいクラス名に置き換えて、必要な動作が得られるまでエッジ インセットを試してください。

于 2013-06-05T17:32:00.393 に答える