zoukankan      html  css  js  c++  java
  • IOS中UICollectionView和UICollectionViewController的用法

    1.新建一个xib描述UICollectionViewCell(比如DealCell.xib),设置好resuse identifier(比如deal

    2.控制器继承UICollectionViewController

    1> 注册xib

    [self.collectionView registerNib:[UINib nibWithNibName:@"DealCell" bundle:nil] forCellWithReuseIdentifier:@"deal"];

    2> 重写init方法

    - (id)init

    {

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

        // 每一个网格的尺寸

        layout.itemSize = CGSizeMake(250, 250); 

        // 每一行之间的间距

        layout.minimumLineSpacing = 20

        // 上下左右的间距

        layout.sectionInset = UIEdgeInsetsMake(10, 20, 40, 80);     return [self initWithCollectionViewLayout:layout];

    }

    3> 实现数据源方法

    #pragma mark 每一组有多少个条目(格子)

    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

    #pragma mark 每一个格子显示什么样的cell

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

    3.UICollectionViewFlowLayout的常见设置 

    1> CGFloat minimumLineSpacing:每一行之间的间距

    2> UIEdgeInsets sectionInset:上下左右周边的间距

    3> CGSize itemSize:每一个网格的大小

    4.UICollectionView的设置

    1> BOOL alwaysBounceVertical:永远支持垂直的弹簧效果(滚动效果,来自UIScrollView的属性)

    5.UITableViewControllerUICollectionViewController的区别

    1> UITableViewController中:self.tableView == self.view

    2> UICollectionViewController中:self.collectionView == self.view中的一个子控件

  • 相关阅读:
    POJ 2251 Dungeon Master(BFS)
    POJ 1321 棋盘问题 (DFS + 回溯)
    POJ 3009 Curling 2.0(DFS + 模拟)
    Codeforces 702D Road to Post Office(模拟 + 公式推导)
    Codeforces 702A Maximum Increase(dp)
    Codeforces 702C Cellular Network(二分)
    Codeforces 702B Powers of Two
    POJ 3083 Children of the Candy Corn (DFS + BFS + 模拟)
    POJ 2488 A Knight's Journey (回溯法 | DFS)
    POJ1094 Sorting It All Out (拓扑排序)
  • 原文地址:https://www.cnblogs.com/changxs/p/3438314.html
Copyright © 2011-2022 走看看