Project 09 - CollectionViewโ˜๐Ÿป

DaYยท2021๋…„ 4์›” 9์ผ
1

iOS

๋ชฉ๋ก ๋ณด๊ธฐ
24/52
post-thumbnail

Collection View

  • Table View์— ๋น„ํ•ด ๋‚˜์—ด์ด ์ž์œ ๋กญ๋‹ค.
  • ์ˆ˜ํ‰, ์ˆ˜์ง์œผ๋กœ ๋‚˜์—ด ๋ฐฉํ–ฅ์„ custom ๊ฐ€๋Šฅํ•˜๋‹ค.
  • Table View์—์„œ Table View Cell์„ ์ด์šฉํ•ด Cell custom์ด ๊ฐ€๋Šฅํ•œ ๊ฒƒ๊ณผ ๊ฐ™์ด Collection View Cell์„ ์ด์šฉํ•ด Cell custom์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
  • Table View์™€ ๋™์ผํ•˜๊ฒŒ DataSource & Delegate ํ”„๋กœํ† ์ฝœ ์ด์šฉํ•˜๋Š” ํŒจํ„ด์„ ์‚ฌ์šฉํ•œ๋‹ค.

Collection View

Collection View ๋˜๋Š” Collection View Controller ์ถ”๊ฐ€

UICollectionViewDataSource

// ์ง€์ •๋œ ์„น์…˜์— ํ‘œ์‹œํ•  ํ•ญ๋ชฉ์˜ ๊ฐœ์ˆ˜๋ฅผ ๋ฌป๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

}
// ์ง€์ •๋œ ์œ„์น˜์— ํ‘œ์‹œํ•  ์…€์„ ์š”์ฒญํ•˜๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

}
// ์„น์…˜์˜ ๊ฐœ์ˆ˜๋ฅผ ๋ฌป๋Š” ๋ฉ”์„œ๋“œ
override func numberOfSections(in collectionView: UICollectionView) -> Int {

}
// ์ง€์ •๋œ ์œ„์น˜์˜ ํ•ญ๋ชฉ์„ ๋‹ค๋ฅธ ์œ„์น˜๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š”์ง€๋ฅผ ๋ฌป๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {

}

UICollectionViewDelegate

// ์„ ํƒ๋  ์ˆ˜ ์žˆ๋Š”์ง€ ๋ฌป๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {

}
// ์ง€์ •๋œ ์…€์ด ์„ ํƒ๋˜์—ˆ์Œ์„ ์•Œ๋ฆฌ๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

}
// ์ง€์ •๋œ ์…€์˜ ์„ ํƒ์ด ํ•ด์ œ๋  ์ˆ˜ ์žˆ๋Š”์ง€ ๋ฌป๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, shouldDeselectItemAt indexPath: IndexPath) -> Bool {

}
// ์ง€์ •๋œ ์…€์˜ ์„ ํƒ์ด ํ•ด์ œ๋˜์—ˆ์Œ์„ ์•Œ๋ฆฌ๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {

}
// ์ง€์ •๋œ ์…€์ด ๊ฐ•์กฐ๋  ์ˆ˜ ์žˆ๋Š”์ง€ ๋ฌป๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, shouldHighlightItemAt indexPath: IndexPath) -> Bool {

}
// ์ง€์ •๋œ ์…€์ด ๊ฐ•์กฐ๋˜์—ˆ์„ ๋•Œ ์•Œ๋ ค์ฃผ๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {

}
// ์ง€์ •๋œ ์…€์ด ๊ฐ•์กฐ๊ฐ€ ํ•ด์ œ๋  ๋•Œ ์•Œ๋ ค์ฃผ๋Š” ๋ฉ”์„œ๋“œ
override func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath) {

}

0๊ฐœ์˜ ๋Œ“๊ธ€