2์ฃผ์ฐจ์ ๋น์ทํ ๊ณผ์ ์ง๋ง, 2์ฃผ์ฐจ์์๋ Stack์ ์ด์ฉํด ๋ทฐ๋ฅผ ์์ฑํ๋ค๋ฉด์ ์ด๋ฒ์๋ CollectionView๋ฅผ ํ์ฉํด ๋ทฐ๋ฅผ ์์ฑํด๋ณด์์ต๋๋ค!
์ด์ 2์ฃผ์ฐจ์ ๋์ผํ๊ฒ, ์์ ํ๋กํ ์์ฑํ๊ธฐ ๋ฒํผ๊ณผ ๋ก๊ณ ์ชฝ์ ๋ฃ๊ธฐ ์ํด headerView๋ฅผ ์ฌ์ฉํ๊ณ ,๋ฐ์๋ scrollView์์ mainContainerView๋ฅผ ์ฑ์ด ๋ค์
๋ฃ๊ณ ์ถ์ ๋ฐฐ๋ ์ด๋ฏธ์ง๋ฅผ ๋ฃ์ด์ฃผ๊ณ
2์ฃผ์ฐจ์ ๋ฌ๋ผ์ง ์ ์ "CollectionView"๋ฅผ ๋ฃ์ด์ฃผ๋ ๊ฒ์ ๋๋ค!!
ํ์ฌ ๋ชจ๋ ์ปฌ๋ ์ ์ ์ด ๋์ผํ ๊ตฌ์ฑ์ผ๋ก ๋์ด ์๊ธฐ์ CollectionView์ ํ๋์ ์ ๋ง ์ฌ๋ ค์ ์์ฑ์ ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค!!
๋ค์๊ณผ ๊ฐ์ด ์ปฌ๋ ์ ๋ทฐ์ ๋ํด delegate์ dataSource์ ๋ํด ์ค์ ์ ํด์ค๋๋ค!3์ฃผ์ฐจ ์ธ๋ฏธ๋์์ ๋ฐฐ์ด๋๋ก ์ฐจ๊ทผ์ฐจ๊ทผ ๋ฐ๋ผํ๋ฉด ๋ทฐ๋ฅผ ๊ตฌ์ฑํ๋๋ฐ๋ ๋ฌธ์ ๊ฐ ์์ง๋ง!
UICollectionViewDelegateFlowLayout
๋ฅผ ํ์ฉํด ์
๋ค์ ํฌ๊ธฐ ๋ฐ ๋ง์ง์ ์ก์๋ณด๋๋ก ํฉ๋๋ค!!
๋ค์๊ณผ ๊ฐ์ ๋ฉ์๋๋ฅผ ํ์ฉํด Cell ์ ํฌ๊ธฐ ๋ฐ ์์น / ๋ง์ง์ ์ก์๋๋ฉด ๋ฉ๋๋ค!!
๋ค ๋ง๊ฒ ์ธํ ํ, ์คํํ์ ๋, ์ฌ๋ฐ๋ฅด๊ฒ ์ถ๋ ฅ ๋์ง ์๋๋ค๋ฉด
์คํ ๋ฆฌ๋ณด๋ UICollectionView ์ธ์คํํฐ์์
"estimate Size"์ ๋ํด์ none์ ์ฒ๋ฆฌํด์ฃผ๋ฉด ์ฝ๊ฒ ๋ ์ด์์์ด ์ํ๋๋๋ก ๊ตฌ์ฑ๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค!
ScrollVIew ๊ฐ์ ๊ฒฝ์ฐ์๋ ๋ด๋ถ container ๋ทฐ์ ์๋ ์์๋ค์ ๋์ด๊ฐ ์ ํํ ๊ฒฐ์ ๋์ด ์์ด์ผ ํฉ๋๋ค. ๋ฐ๋ผ์ ์คํฌ๋กค ๋ทฐ ์์ ๋ฐฐ๋ ์ด๋ฏธ์ง๋ฅผ ๋ฃ๊ณ , ์ปฌ๋ ์ ๋ทฐ๋ฅผ ๋ฃ๊ณ ์งค ๋, ๋์ด๋ฅผ ๊ฒฐ์ ํด์ผ ์ ์ฒด๊ฐ ์คํฌ๋กค์ด ๊ฐ๋ฅํฉ๋๋ค!!
์ปฌ๋ ์ ๋ทฐ์ ๋์ด๊ฐ ๊ฒฐ์ ๋์ง ์์ ์์์ ์๋ ์คํฌ๋กค๋ทฐ๋ ์ปฌ๋ ์ ๋ทฐ์ ๋์ด๋ฅผ ๋ชจ๋ฅด๊ธฐ๋๋ฌธ์ ์ ์ฒด ์คํฌ๋กค์ด ๋์ง ์๊ณ ๋ด๋ถ์ ์๋ ์ปฌ๋ ์ ๋ทฐ์์๋ง ์คํฌ๋กค์ด ๊ฐ๋ฅํด์ง๋๋ค,,
์ปฌ๋ ์ ๋ทฐ์๋ ์คํฌ๋กค์ด ๋จน๊ณ , ์์ ์คํฌ๋กค๋ทฐ์๋ ์คํฌ๋กค์ด ๋จน๋๋ค๋ฉด ๋ฏธ๋ฌํ๊ฒ ์คํฌ๋กค ์ก์ ์ด ์ด์ํ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค!
์ด๋ ๊ฒ ๋์์ ๊ฒฝ์ฐ์๋, ๋ด๋ถ ์ปฌ๋ ์ ๋ทฐ์ ๋ํด height ๋ฅผ ๊ฑธ๊ณ , User Interaction, ์ฆ ์ปฌ๋ ์ ๋ทฐ์ ๋ํด ์คํฌ๋กค์ ์๋จน๊ฒ ํ ๋ค์
์ปฌ๋ ์ ๋ทฐ์ ๋ํด ๋์ด๋ฅผ ๋ญ๋ญํ๊ฒ... ์ ๋นํ๊ฒ.. ๋๊ฒ ์ค์ ํด์ฃผ๋ฉด ์คํฌ๋กค์ด ๊น๋ํ๊ฒ ๋๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค!!
(์ ์ฒด ์ฝ๋)
//
// ViewController.swift
// thirdWeek_Assignment
//
// Created by ์ก์งํ on 2020/11/01.
//
import UIKit
class ViewController: UIViewController {
var userDataList : [userData] = []
@IBOutlet weak var userCollectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
settingCollectionView()
settingData()
}
func settingCollectionView()
{
self.userCollectionView.delegate = self
self.userCollectionView.dataSource = self
}
func settingData()
{
self.userDataList.append(contentsOf: [
userData(name: "์ด์ฃผํ", imageName: "juhyeok", description: "#hereis#์์#๋ด๊ฟ์#์ฌ๊ณผ๋์ฅ#ENFP"),
userData(name: "๊น๋์ฐ", imageName: "nayeon", description: "#์ด์ ๋งํ๊ธฐ #์ฌ๋ฌ๋ถ๋ค์ด๋_์นํด์ง๊ณ _์ถ์ด์#๋ฒ๊ฐ์คํฐ๋ํ์"),
userData(name: "์ํํ", imageName: "peace", description: "#ํธ๋ํผ์ฐ #์ด๋ํผ์ฐ #๋ฐฐ๊ผฝ๋๋#ํฌ๋ฆฐ์ด #sson_peace7"),
userData(name: "์ ํฌ์", imageName: "heesoo", description: "#์ด๋ฌด๊ฟ๋๋ฌด #์ ์ด๋ฌด #ํ์ฌ_์์์ค #ํ"),
userData(name: "๋ฐ์ธ์", imageName: "saeeun", description: "#๋ง #์์๋ #์ฒ์์
๋๋ค"),
userData(name: "ํ์ธ", imageName: "wool", description: "#ENFP #STORM #์ธํฌ๋ฐ์ค #@hwooolll #ํ๋์ฝ๋ ํฐ"),
userData(name: "๊นํ์", imageName: "hansol", description: "#๊ณ ๊ฐ์ค์ฌ#๊ณ ๊ฐํ๋๋ฐ์ดํฐ๊ธฐ๋ฐํ#UX๋์์ด๋#์๋๋น,,"),
userData(name: "๋ฐฐ๋ฏผ์ฃผ", imageName: "minju", description: "#๋ํ์ฅ #๊ฐ์์ด๋ #์ต์ข
๋ชฉํ๋ํ๋ณต"),
userData(name: "์ต์ํ", imageName: "younghun", description: "#์ํ์งฑ #์ํธ3ํ์ฐจ #์ฑ์ผ_์๋ฆฌ_๊ฐ๋ฐ์ #UX/UI"),
userData(name: "๊ฐ๋ฏผ๊ตฌ", imageName: "minguru", description: "#๋ฐ๋งน #์ํ์ฅ #์ด๋๋ต๋_๊ท์ฌ์ด๊ฑฐ์ข์ํจ #์ง๋ฐ๋ น #ํ๋น"),
userData(name: "์ด์ ์ฐ", imageName: "yeonjeong", description: "#ํ๋ ์ด์คํฝ #ENFJ #๊ธฐํ_๋์์ธ_๊ฐ๋ฐ_๋ค"),
userData(name: "ํ์ค์ฝ", imageName: "junyeop", description: "#26๊ธฐ์๋ฒ #27๊ธฐ์น #์ต์ด_๋๊ฐ๋ฉด_์ด๋ป๊ฒ๋ ๊น? ##")
])
}
}
extension ViewController : UICollectionViewDelegate
{
}
extension ViewController : UICollectionViewDataSource
{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return userDataList.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let userCell = collectionView.dequeueReusableCell(withReuseIdentifier: "userCell", for: indexPath) as? userCollectionCell else {return UICollectionViewCell() }
userCell.settingData(name: userDataList[indexPath.row].name, imageName: userDataList[indexPath.row].imageName, description:userDataList[indexPath.row].description )
return userCell
}
}
extension ViewController : UICollectionViewDelegateFlowLayout
{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = (self.userCollectionView.frame.width - 27) / 2
let height = width * 1.5
return CGSize(width: width, height: height)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout:
UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout:
UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout:
UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}