zoukankan      html  css  js  c++  java
  • iOS collectionView自适应高度estimatedItemSize

    collectionView自适应高度 有两个点需要注意
    1.设置layout的estimatedItemSize属性

        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        flowLayout.estimatedItemSize = CGSizeMake((SCREEN_WIDTH-24), autoSize(150));
    

    2.在cell中重新并实现preferredLayoutAttributesFittingAttributes:方法【这个方法经常被遗漏,这样算出来的宽高就会有问题】

    -(UICollectionViewLayoutAttributes*)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes*)layoutAttributes {
        [self setNeedsLayout];
        [self layoutIfNeeded];
        CGSize size = [self.contentView systemLayoutSizeFittingSize: layoutAttributes.size];
        CGRect cellFrame = layoutAttributes.frame;
        cellFrame.size.height= size.height;
        layoutAttributes.frame= cellFrame;
        return layoutAttributes;
    }
    
  • 相关阅读:
    程序员掌握的单词汇总
    Django--基础补充
    C#入门概述
    python常用模块
    软件开发经验之谈
    p7.BTC-挖矿总结
    p6.BTC-挖矿难度
    p5.BTC-网络
    p4.BTC-实现
    p3.BTC-协议
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/15692657.html
Copyright © 2011-2022 走看看