UICollectionView cell subviews do not resize

后端 未结 10 1738
佛祖请我去吃肉
佛祖请我去吃肉 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 00:49

    In another project without xibs i subclassed UICollectionViewCell and did this for the same effect:

    #import "CVcell.h"
    
    @implementation CVcell
    
    @synthesize cellImage;
    
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
    
            CGFloat cellSize = self.contentView.bounds.size.width;
            cellImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, cellSize, cellSize)];
            [cellImage setClipsToBounds:YES];
    
            cellImage.translatesAutoresizingMaskIntoConstraints = NO;
            cellImage.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
            [self.contentView addSubview:cellImage];
    
        }
        return self;
    }
    
    @end
    

提交回复
热议问题