์ง์ฐ๊ธฐ ์๊น์์ ๋จ๊ฒจ๋ ๋๋ collectionViewLayout
private lazy var collectionView: UICollectionView = {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: createLayout())
collectionView.register(PokemonCell.self, forCellWithReuseIdentifier: PokemonCell.id)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.backgroundColor = #colorLiteral(red: 0.4334821701, green: 0.1452553272, blue: 0.1374996305, alpha: 1)
return collectionView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.mainRed
configureUI()
}
private func createLayout() -> UICollectionViewLayout {
//์์ดํ
์ฌ์ด์ฆ ์ ์ - ๊ฐ ์์ดํ
์ ๊ฐ ๊ทธ๋ฃน ๋ด์์ ์ ์ฒด ๋๋น์ ๋์ด๋ฅผ ์ฐจ์ง. (1.0 = 100%).
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
//๊ทธ๋ฃน ์ฌ์ด์ฆ ์ ์
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.3), heightDimension: .absolute(100))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
//์น์
์ฌ์ด์ฆ ์ ์
let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .continuous //์ฐ์ ์คํฌ๋กค
section.interGroupSpacing = 10 //๊ทธ๋ฃน๊ณผ ๊ทธ๋ฃน ์ฌ์ด์ ๊ฐ๊ฒฉ
section.contentInsets = .init(top: 10, leading: 10, bottom: 10, trailing: 10)
return UICollectionViewCompositionalLayout(section: section)
}
๋ทํ๋ฆญ์ค ํด๋ก ์ฝ๋ฉ์์ ๋ฐฐ์ด UICollectionViewLayout์ผ๋ก ์ธ๋ก ์ปฌ๋ ์ ๋ทฐ๋ฅผ ๋ง๋ค์ด๋ณด์๋๋ฐ
์ ๋์ง๋ ์์์๋ฟ๋๋ฌ, ํค๋๋ ์ฌ๋ฌ ์น์ ์ ์ฌ์ฉํ๋๊ฒ ์๋๋ค ๋ณด๋ ํจ์จ์ ์ด์ง๋ ๋ชปํ๋ค.
์ด๋ ๊ฒ ์ปค์คํ ํ๋ ๋ฐฉ๋ฒ์ ์ธ๋ก ์คํฌ๋กค์ ๊ตฌํํ ์ ์๋ ๊ฒ์ธ๊ฐ...
๊ธฐ๋ณธ ์ปฌ๋ ์ ๋ทฐ๋ณด๋ค ์ฌ์ฉ๋ฒ์ด ๋ณต์กํด์ ์ดํดํ๋๋ฐ ์๊ฐ์ด ๊ฝค ๊ฑธ๋ ธ๋คใ
๊ทผ๋ฐ ์ด ์ฝ๋๋ฅผ ๋ฒ๋ฆฌ๋ ค๋ ๋ง์ด ์ํ๋ค..ใ ใ ใ ใ
์ธ์ ๋ ์ธ ์ค ๋ชจ๋ฅด๊ฒ ์ง๋ง ์ผ๋จ ๋จ๊ฒจ๋ ๋ฌ๋ณธ๋ค....ใ
[MVVM] Model์์ Class๋์ Struct๋ฅผ ์ฌ์ฉํ๋ ์ด์ (0) | 2024.08.04 |
---|