tutorial horizontal collection ios header uicollectionview flowlayout

ios - tutorial - Posición del encabezado UICollectionView en modo de dirección de desplazamiento horizontal con diseño de flujo



uicollectionview swift 4 (2)

Resolví el problema usando DateFlowLayout .

Vea cómo lo configuré en esta otra respuesta .

Tengo ios UICollectionView con diseño de flujo con dirección de desplazamiento horizontal. En esta situación, la posición típica del encabezado está en el lado izquierdo de las celdas.

Quiero hacer un encabezado en la parte superior de las celdas de sección

¿Tienes alguna idea de cómo puedo hacer esto?


Creo que puedes obtener lo que necesitas usando el comportamiento estándar para el encabezado.

Configúrelo (probablemente en viewDidLoad):

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.headerReferenceSize = CGSizeMake(self.collectionView.bounds.size.width, 30); // other setup [self.collectionView setCollectionViewLayout:flowLayout];

Luego responda una vista de encabezado:

#define MY_HEADER_LABEL_TAG 128 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind: UICollectionElementKindSectionHeader withReuseIdentifier:@"SectionHeader" forIndexPath:indexPath]; UILabel *label = (UILabel *)[headerView viewWithTag:MY_HEADER_LABEL_TAG]; if (!label) { label = [[UILabel alloc] initWithFrame:CGRectInset(headerView.bounds, 5, 5)]; label.tag = MY_HEADER_LABEL_TAG; label.font = [UIFont boldSystemFontOfSize:12]; label.textColor = [UIColor darkGrayColor]; [headerView addSubview:label]; } label.text = [NSString stringWithFormat:@"Section %d", indexPath.section]; return headerView; }