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
| // UICollecionViewController | |
| class UICollectionViewController : UIViewController | |
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
| // collectionView | |
| class UICollectionView : UIScrollView | |
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
| // MARK: flowLayout | |
| let flowLayout = UICollectionViewFlowLayout() | |
| flowLayout.sectionHeadersPinToVisibleBounds = true |
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
| extension ViewController: UICollectionViewDataSource { | |
| // MARK: cell count | |
| func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
| return palette.count | |
| } | |
| // MARK: cell | |
| func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
| guard let cell: CustomCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "\(CustomCollectionViewCell.self)", for: indexPath) as? CustomCollectionViewCell else { | |
| return UICollectionViewCell() |
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
| extension ViewController: UICollectionViewDelegate { | |
| // MARK: selected | |
| func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
| print("\(indexPath.item)번 Cell 클릭") | |
| } | |
| } |
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
| extension ViewController: UICollectionViewDelegateFlowLayout { | |
| // MARK: cellSize | |
| func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
| let collectionViewWidth = collectionView.bounds.width | |
| let cellItemForRow: CGFloat = 3 | |
| let minimumSpacing: CGFloat = 2 | |
| let width = (collectionViewWidth - (cellItemForRow - 1) * minimumSpacing) / cellItemForRow | |
| return CGSize(width: width, height: width) |
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
| import UIKit | |
| class CustomCollectionViewCell: UICollectionViewCell { | |
| weak var imageView: UIImageView? | |
| override init(frame: CGRect) { | |
| super.init(frame: frame) | |
| let imageView = UIImageView() | |
| self.imageView = imageView |
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
| import UIKit | |
| class ViewController: UIViewController { | |
| // MARK: - Property | |
| let palette: [UIColor] = [.red, .orange, .yellow, .green, .blue] | |
| // MARK: - View | |
| private var collectionView: UICollectionView? | |
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
| let nextviewController = SecondViewController() | |
| nextviewController.modalPresentationStyle = .fullScreen | |
| nextviewController.modalTransitionStyle = .partialCurl | |
| present(nextviewController, animated: true) |
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
| Observable.just(data) // Observable을 만들어 주고 | |
| .bind(to: tableView.rx.items()) // tableView.rx.items()를 바인딩 해주고 | |
| .disposed(by: disposeBag) // disposeBag에 넣어주면 됩니다. |
OlderNewer