UICollectionView header根据内容设置高度

直接在collectionView referenceSizeForHeaderInSection方法中计算header内容的高度,其中getHeaderHeight为根据所有文字图片内容相加后得出的header高度

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(Screen_Width, [self getHeaderHeight]);
    } else {
        return CGSizeMake(Screen_Width, 65);
    }
    return CGSizeMake(0, 0);
}

你可能感兴趣的:(UICollectionView header根据内容设置高度)