UICollectionView cell subviews do not resize

后端 未结 10 1676
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 00:25

In a CollectionView, some cells should have an additional subview or layer. The CollectionView can be told to resize it\'s cells, thus all content

10条回答
  •  借酒劲吻你
    2020-11-29 01:08

    I ran into the same issue just now.

    When using the UICollectionViewFlowLayoutDelegate method to set the cell size depending on device and device-orientation, the size would be calculated properly but subviews would not resize to fill the newly size cell. The effect was a large blank cell with small subviews that don't fill the cell's bounds / remain the size equal to their current value in the xib file.

    I solved this by doing the following in awakeFromNib:

    - (void)awakeFromNib
    {
        [super awakeFromNib];
    
        self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        self.contentView.translatesAutoresizingMaskIntoConstraints = YES;
    }
    

    Prior to doing this, the contentView mask was nil.

提交回复
热议问题