分享

用Storyboard慢速创建UICollectionView

 昵称v8JFa 2016-06-23

Tip: 致敬@简书

>参照原创文章:

>/collectionview/

最终效果



新建一个项目

1. 选择Single View Application模板


New Project

2. 删除Main.storyborad中的默认ViewController


Delete View Controller Scene

3. 删除文件列表中的ViewController.h && ViewController.m


Delete XX.h&&XX.m


新建并设置Collection View Controller

1. 拖拽一个Collection View Controller到Main.Storyboard中


Drag Collection View Controller

2. 在Attributes Inspector中,设置为Is Initial View Controller


Set Initial

3. New File , 继承自UICollectionViewController


New Controller

4. 回到Main.storyboard,设置Collection View Controller的Custom Class


Set Custom Class


新建并设置Collection View Cell

1. New File,继承自UICollectionViewCell


New Cell Class

2. 回到Main.storyborad,设置Collection View里Cell视图的Custom Class


Set Custom Class

3. 布置Cell,调整Cell的大小,添加ImageView并配上合适的图片,添加Label


Config Cell


4. 关联Cell视图中的Image View 和 Label控件到CollectionViewCell.h


Outlet

实现协议

1. 返回每个Section的item的个数


Return Item Number

2. 返回Cell


Return Cell

关键点

1. kReuseId = "Mycell",这里的值需要和下图中的配置一致


Key1

2. 使用Identifier后,不能用代码注册Cell(你可以试一试)


Key2

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多