## ๐Ÿง ๋ฌธ์ œ์™€ ํ•ด๊ฒฐ ### M1 CocoaPod ์„ค์น˜ ๋ฌธ์ œ -> iTerm ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ > `Rosetta๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—ด๊ธฐ` ์ฒดํฌ -> `brew install cocoapods` or `sudo gem install cocoapods` -> `sudo arch -x86_64 gem install ffi` -> Podfile์ด ์žˆ๋Š” ํ”„๋กœ์ ํŠธ directory์—์„œ ํ„ฐ๋ฏธ๋„ ์—ฐ ํ›„, `arch -x86_64 pod install` --- ### CollectionView ์˜คํ† ๋ ˆ์ด์•„์›ƒ ์—๋Ÿฌ **๋ฌธ์ œ** ```swift= let itemSize = NSCollectionLayoutSize( widthDimension: NSCollectionLayoutDimension.fractionalWidth(1), heightDimension: .estimated(40) // ๋ฌธ์ œ์˜ ์›์ธ ) ``` - `NSCollectionLayoutDimension.estimated(40)` ์ฝ”๋“œ๊ฐ€ ๊ธฐ๋ณธ ๋†’์ด ๊ฐ’์„ ์˜๋ฏธํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๊ณ  ์‹ค์ œ View ์˜ ํฌ๊ธฐ์— ๋”ฐ๋ผ ๊ฐ€๋ณ€์ ์œผ๋กœ ๋ณ€ํ™”ํ•  ๊ฒƒ์œผ๋กœ ๊ธฐ๋Œ€ํ•จ - Cell ์˜ ๋†’์ด๋ฅผ 130dp ๋กœ ์„ค์ •ํ•˜๊ธฐ ์œ„ํ•ด Cell ์˜ ํ•˜์œ„ View ์˜ `HeightAnchor` ๋ฅผ 130 ์œผ๋กœ ๊ณ ์ • **ํ•ด๊ฒฐ** - `NSCollectionLayoutDimension.estimated(40)` ๋ณด๋‹ค ์‹ค์ œ ์‚ฌ์ด์ฆˆ๊ฐ€ ๋” ํฌ๋ฉด AutoLayout ์—๋Ÿฌ๋ฅผ ๋ฐœ์ƒํ•˜๋Š” ๊ฒƒ์„ ๋ฐœ๊ฒฌํ•จ - ์‹ค์ œ ์‚ฌ์ด์ฆˆ๊ฐ€ estimated ์‚ฌ์ด์ฆˆ ๋ฒ”์œ„ ์ด๋‚ด์ด๋ฉด ์‹ค์ œ View ์˜ ํฌ๊ธฐ๋กœ ํ™”๋ฉด์— ํ‘œ์‹œ๋˜๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ ๋จ **์‹œ๋„** 1. `NSCollectionLayoutDimension.estimated(40)` ์œผ๋กœ ์„ค์ •ํ•˜๊ณ  Cell ์˜ Image View ์˜ `HeightAnchor` ๋ฅผ `greaterThanEqualTo` ๋กœ ์„ค์ •ํ•˜๋‹ˆ AutuLayout ์—๋Ÿฌ๊ฐ€ ์‚ฌ๋ผ์ง€๊ณ  ์›ํ•˜๋Š” ๊ฒฐ๊ณผ๋ฅผ ์–ป์Œ. ๊ทธ๋Ÿฌ๋‚˜ ImageView ์˜ image ์˜ ์‹ค์ œ ํฌ๊ธฐ์— ์˜ํ–ฅ์„ ๋ฐ›์•„ ์‹ค์ œ Cell ์˜ ํฌ๊ธฐ๋Š” 130 ๋ณด๋‹ค ์ปค์ง - `EqualTo` ์˜ต์…˜ ์‚ฌ์šฉ ์‹œ estimated ๊ฐ’ ์ดํ•˜์—ฌ์•ผ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒ๋˜์ง€ ์•Š๋Š”๋‹ค. - `greaterThanEqualTo` ์‚ฌ์šฉ ์‹œ estimated ๊ฐ’์„ ์ดˆ๊ณผํ•  ์ˆ˜ ์žˆ๋‹ค. 3. 1. ์˜ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด estimated ๊ฐ’์„ 130์œผ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  Image View ์˜ `HeightAnchor` ๋ฅผ `greaterThanEqualTo` ์—์„œ `EqualTo` ๋กœ ๋ณ€๊ฒฝ --- ### CollectionViewCell Register ์•ˆํ•ด์„œ ํ™”๋ฉด์ด ์•ˆ๋„˜์–ด๊ฐ **๋ฌธ์ œ** - ์Šคํ† ๋ฆฌ๋ณด๋“œ์—์„œ cell์„ ๋งŒ๋“ค๊ณ  identifier๋ฅผ ์ง€์ •ํ•ด์ค˜์„œ ๋”ฐ๋กœ register๋ฅผ ํ•ด์ฃผ์ง€ ์•Š์Œ - cell์„ ํด๋ฆญ ํ–ˆ์„ ๋•Œ, `didSelectItemAt:` ํ•จ์ˆ˜๊ฐ€ ๋ถˆ๋ฆฌ์ง€ ์•Š์Œ **ํ•ด๊ฒฐ** ```swift= collectionView.register(ProductDetailCell.self, forCellWithReuseIdentifier: ProductDetailCell.identifier) ``` - view controller์—์„œ cell์„ ๊ฐ™์€ ์ด๋ฆ„์œผ๋กœ register ํ•ด์ฃผ๋Š” ๊ฒƒ์œผ๋กœ ํ•ด๊ฒฐ --- ### Badge ๊ฐœ์ˆ˜์— ๋”ฐ๋ฅธ ํฌ๊ธฐ ์กฐ์ ˆ ```swift self.adjustsFontSizeToFitWidth = true self.minimumScaleFactor = 0.5 ``` - ๊ณต๊ฐ„์ด ๋ถ€์กฑํ•˜๋ฉด ํฐํŠธ์˜ ์‚ฌ์ด์ฆˆ๋ฅผ 0.5๋ฐฐ๊นŒ์ง€ ์ค„์ผ ์ˆ˜ ์žˆ๋„๋ก ์ˆ˜์ •ํ•˜์—ฌ ํ•ด๊ฒฐ -> ์—ฌ์ „ํžˆ badge๊ฐ€ ๋„ˆ๋ฌด ๋งŽ์•„์ง€๊ฑฐ๋‚˜ ํ™”๋ฉด์ด ์ž‘์•„์ง€๋ฉด ํฐํŠธ๊ฐ€ ์ž˜๋ฆฌ๋Š” ๋ฌธ์ œ๊ฐ€ ๋‚จ์•„์žˆ์Œ