Created
May 12, 2017 03:27
-
-
Save helloworldsmart/52acb5c037d5c971486b0ddb0c49e4af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 必須實作的方法:每個 cell 要顯示的內容 | |
| func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
| // 依據前面註冊設置的識別名稱 "Cell" 取得目前使用的 cell | |
| let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! MyCollectionViewCell | |
| // 第一個在陣列取0 | |
| guard indexPath.item != 0 else { | |
| cell.backgroundColor = .brown | |
| return cell | |
| } | |
| // 設置 cell 內容 (即自定義元件裡 增加的圖片與文字元件) | |
| cell.imageView.image = UIImage(named: "0\(indexPath.item + 1).jpg") | |
| cell.titleLabel.text = "0\(indexPath.item + 1)" | |
| return cell | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment