gpt4 book ai didi

objective-c - 动态更改 UICollectionReuseableView(集合部分标题)的高度

转载 作者:太空狗 更新时间:2023-10-30 03:09:43 25 4
gpt4 key购买 nike

我正在尝试为 UICollectionView 动态设置节标题的高度,但是使用下面的代码,我没有看到任何变化。 View 是用正确的项目绘制的,但高度不会改变。抱歉,如果这是一个重复的问题,但我似乎找不到任何与 UICollectionView 对象相关的内容。提前致谢。

- (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;
}

最佳答案

假设您使用的是流式布局,您的委托(delegate)应实现以下功能:

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

您可以为每个标题返回不同的大小。在水平滚动的 Collection View 中,只使用宽度。在垂直滚动的中,只使用高度。未使用的值将被忽略——您的 View 将始终被拉伸(stretch)以分别填充水平/垂直 Collection View 的整个高度/宽度。

页脚也有相应的方法。

关于objective-c - 动态更改 UICollectionReuseableView(集合部分标题)的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14383995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com