美文网首页
UICollectionView的创建

UICollectionView的创建

作者: hncjliyingjie | 来源:发表于2018-01-07 16:15 被阅读17次
    //网格
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];//滚动方向
    layout.itemSize = CGSizeMake(KItemWidth, 165);
    layout.headerReferenceSize = CGSizeMake(KviewWidth, 50);
    layout.sectionInset = UIEdgeInsetsMake(20, 10, 50, 10);
    layout.minimumInteritemSpacing = 1;
    layout.minimumLineSpacing = 10;
    
    layout.sectionHeadersPinToVisibleBounds = YES;//头部是否跟随移动
    self.flowLayout = layout;
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    [self.view addSubview:collectionView];
    self.collectionView = collectionView;
    
    collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    [collectionView registerClass:[SZUploadCollectionViewCell class] forCellWithReuseIdentifier:@"SZ"];
    [collectionView registerClass:[SZZeroCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
    collectionView.delegate = self;
    collectionView.dataSource = self;
    
    collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [[self.mainViewModel.getListDataCommand execute:nil] subscribeNext:^(id x) {
            [self reloadData];
              //            [self.collectionView reloadData];
        }];
        [self.collectionView.mj_header endRefreshing];
    }];

    相关文章

      网友评论

          本文标题:UICollectionView的创建

          本文链接:https://www.haomeiwen.com/subject/sotmnxtx.html