您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 基礎知識 >> iOS 基礎知識

iOS UICollectionView 基本用法

編輯:iOS 基礎知識

UICollectionView 可用來建立網格、卡片或自訂排版。使用方式與 UITableView 類似,需要設定 layout、dataSource 與 delegate。

建立方式

可繼承 UICollectionViewController,也可在一般 UIViewController 中建立 UICollectionView。後者需自行加入畫面並設定 delegate。

初始化

先建立 UICollectionViewFlowLayout,再用 initWithFrame:collectionViewLayout: 建立 collection view,註冊 cell,設定背景色、delegate 與 dataSource。

代理方法

numberOfItemsInSection 回傳每節項目數;cellForItemAtIndexPath 回傳 cell;didSelectItemAtIndexPath 處理點擊。FlowLayout 的 delegate 可設定項目大小與 section 間距。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved