usar titulos tag que hacer etiquetas como objective-c ios6 xcode4.5

objective c - titulos - cambie la altura de un UICollectionReuseableView(encabezado de sección de colección) dinámicamente



que es un tag h2 (3)

Pruebe algo como esto:

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *header = [siteMapCollection dequeueReusableSupplementaryViewOfKind: UICollectionElementKindSectionHeader withReuseIdentifier: @"headerID" forIndexPath: indexPath]; NSString *headerText = @"This is my header"; UIFont *labFont = [UIFont fontWithName: @"HelveticaNeue-CondensedBold" size: 20.0]; CGSize textSize = [dummyText sizeWithFont: labFont]; UILabel *headerLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, header.frame.size.height - (textSize.height + 12), header.frame.size.width, textSize.height + 8)]; [headerLabel setFont: labFont]; [header addSubview: headerLabel]; return header; }

Estoy tratando de establecer la altura de los encabezados de las secciones de UICollectionView forma dinámica, pero con el siguiente código, no veo que cambie nada. La vista se dibuja con los elementos correctos, pero la altura no cambiará. Lo siento si esta es una pregunta repetida, pero parece que no encuentro nada relacionado específicamente con el objeto UICollectionView . Gracias por adelantado.

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { PhotoVideoHeaderCell *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"videoHeaderView" forIndexPath:indexPath]; if (indexPath.section == 0) { // photos [headerView setSection:@"Photo"]; } else { [headerView.VehicleDetailView removeFromSuperview]; CGRect frame = headerView.frame; frame.size.height = 60; [headerView setFrame:frame]; [headerView setNeedsDisplay]; [headerView setBackgroundColor:[UIColor grayColor]]; [headerView setSection:@"Video"]; } return headerView; }


Respuesta aceptada en Swift 3 y 4:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { return CGSize(width: collectionView.frame.size.width, height: 250) }


Su delegado debe implementar la siguiente función, suponiendo que esté utilizando un diseño de flujo:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;

Puede devolver un tamaño diferente para cada encabezado. En vistas de colección de desplazamiento horizontal, solo se utiliza el ancho. En los que se desplazan verticalmente, solo se usa la altura. El valor no utilizado se ignora: su vista siempre se alargará para llenar el alto / ancho completo de las vistas de colección horizontal / vertical, respectivamente.

Hay un método correspondiente para los pies de página, también.