为UICollectionView添加headView

2021-05-07  本文已影响0人  张无奈

- (void)viewDidLoad {

    [super viewDidLoad];

     [self contentInsetHeaderView];

}

- (void)contentInsetHeaderView {

    CGFloatheader_y =120;

    self.coll.contentInset = UIEdgeInsetsMake(120, 0, 0, 0);

    self.photo.frame = CGRectMake(0, -header_y,WIDTH, header_y);

    [self.coll addSubview:self.photo];

    [self.coll setContentOffset:CGPointMake(0, -header_y)];

}

#pragma mark- LazyLoad

- (UICollectionView *)coll{

    if(!_coll) {

        UICollectionViewFlowLayout *Layout = [[UICollectionViewFlowLayout alloc] init];

        Layout.minimumLineSpacing = Layout.minimumInteritemSpacing = 12;

        _coll = [[UICollectionView alloc] initWithFrame:CGRectMake(12, 0, WIDTH - 24, MyViewHEIGHT) collectionViewLayout:Layout];

        _coll.backgroundColor = [UIColor whiteColor];

        [_coll MaskToBounds:8];

        _coll.alwaysBounceVertical = YES;

        _coll.showsHorizontalScrollIndicator = NO;

        _coll.showsVerticalScrollIndicator = NO;

        [_coll registerClass:[MedicalRecordsManaCell class] forCellWithReuseIdentifier:@"MedicalRecordsManaCell"];

        _coll.dataSource=self;

        _coll.delegate=self;

    }return_coll;

}

上一篇 下一篇

猜你喜欢

热点阅读