Подтвердить что ты не робот

Удалите пространство между разделами в коллекции

Как отрегулировать расстояние между разделами просмотра коллекции.

enter image description here

4b9b3361

Ответ 1

Высота заголовка можно отрегулировать, отрегулировав параметры макета коллекции. Ниже приведен код, который отлично работает.

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section 
{
    if ([[sectionHeaderArray objectAtIndex:section] boolValue]) {
        return UIEdgeInsetsMake(10, 10, 10, 10);
    }
      return UIEdgeInsetsZero;
}

Ответ 2

Вы можете использовать метод для реализации этого:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section 
{
    //{top, left, bottom, right}

    if ([[sectionHeaderStatusArray objectAtIndex:section] boolValue]) {
        return UIEdgeInsetsMake(23, 19, 46, 14);
    }

      return UIEdgeInsetsZero;
}

Ответ 3

Высота заголовка можно отрегулировать, отрегулировав параметры макета коллекции. Ниже приведен код для него:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section 
{
    //{top, left, bottom, right}

    if ([[sectionHeaderArray objectAtIndex:section] boolValue]) {
        return UIEdgeInsetsMake(10, 10, 10, 10);
    }

      return UIEdgeInsetsZero;
}

Ответ 4

Это вопрос макета, поэтому ответ будет в любом макете, который вы используете для представления коллекции. Если вы используете UICollectionViewFlowLayout, вам нужно установить sectionInset. например.

self.collectionView.collectionViewLayout.sectionInset = UIEdgeInsetsZero;

Ответ 5

Попробуй это:

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section 
{
    if ([[sectionHeaderArray objectAtIndex:section] boolValue]) {
        return UIEdgeInsetsMake(top, left, bottom, right);
    }
      return UIEdgeInsetsZero;
}

Ответ 6

Вот версия Swift 4.2.

Это позволяет вам устанавливать различные конфигурации вставок для разных разделов.

/// Formats the insets for the various headers and sections.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
    if section == 0 {
        // No insets for header in section 0
        return UIEdgeInsets.zero
    } else {
        // Normal insets for collection
        return UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0)
    }
}