HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 自动调整UICollectionView标头大小大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试为待办事项列表类型的应用程序制作详细信息屏幕.这是详细屏幕目前的样子:

ios – 自动调整UICollectionView标头大小

这是一个带有标题的UICollectionViewController.标头包含2个UILabel对象和一个UITextView对象.这些对象的布局由垂直UIStackView管理. UIView用于设置白色背景.

我在运行时定义此UICollectionReusableView的高度时遇到了一些困难.任何建议表示赞赏.

解决方法

这有点像黑客,但似乎有效.

// showhere to keep a reference
UICollectionReusableView * _cachedHeaderView;


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind aTindexPath:(NSIndexPath *)indexPath{

    if(!_cachedHeaderView){
        // dequeue the cell from storyboard
        _cachedHeaderView = [collectionView dequeueReusableCellWithReusEIDentifier:[NSString StringWithFormat:@"header_cell"] forIndexPath:indexPath];

        // set captions/images on the header etc...

        // tell the collectionview to redraw this section
        [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section]];
    }

    return _cachedHeaderView;
}


- (CGSizE)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{

    // once there is a reference ot the view,use it to figure out the height
    if(_cachedHeaderView){
        return [_cachedHeaderView systemLayoutSizeFitTingSize:collectionView.bounds.size withHorizontalFitTingPriority:UILayoutPriorityrequired verticalFitTingPriority:UILayoutPriorityDefaultLow];

    }

    // a placeholder value just to get the dequeueReusableCellWithReusEIDentifier to work 
    return CGSizeMake(collectionView.bounds.size.width,100);
}

大佬总结

以上是大佬教程为你收集整理的ios – 自动调整UICollectionView标头大小全部内容,希望文章能够帮你解决ios – 自动调整UICollectionView标头大小所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。