๐ ๋ค์ฏ๋ฒ์งธ ํ๋ก์ ํธ (2)
Apple Framework List ์ฑ์ ๋ ๋ง์ ธ๋ณด์!
1๏ธโฃ ๊ฐ Framework Cell ๋ค์ด ํด๋ฆญ๋์์ ๋ ํจ๊ณผ
- UICollectionViewDelegate ์ didSelectItemAt ๋ฉ์๋ : Item์ ์ ํํ์ ๋ ํธ์ถ๋๋ method
// item์ด ์ ํ๋์์ ๋ ํจ๊ณผ ๋ฃ๊ธฐ
extension FrameworkListViewController: UICollectionViewDelegate{
// item์ด ์ ํ๋์์ ๋ ํธ์ถ๋๋ method
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let framework = list[indexPath.item] // ๋ช๋ฒ์งธ item์ธ์ง?
print(">>>> selected : \(framework.name)")
}
}
-> console์ print๋ฌธ ์ถ๋ ฅ!
2๏ธโฃ 2์ด๋ก ๋ง๋ค๊ธฐ
let width = (collectionView.bounds.width - interItemSpacing * 1 - padding * 2) / 2
3๏ธโฃ 4์ด๋ก ๋ง๋ค๊ธฐ
let width = (collectionView.bounds.width - interItemSpacing * 3 - padding * 2) / 4
โฐ ๊ธ์๋ ์์๊ฒ ํ์
// FrameworkCell.swift
import UIKit
class FrameworkCell: UICollectionViewCell {
// ...
override func awakeFromNib() {
super.awakeFromNib()
nameLabel.numberOfLines = 1
// font ์ฌ์ด์ฆ๋ฅผ ์
์ ๋ฐ๋ผ ๋ง๊ฒ ์กฐ์
nameLabel.adjustsFontSizeToFitWidth = true
}
// ...
}
3๏ธโฃ ๋ค์ 3์ด๋ก ๋ฐ๊พธ๊ณ ๋ค๋น๊ฒ์ด์ ๋ฐ ํ์ดํ ๋ฐ๊พธ๊ธฐ ( ์ฝ๋ ์์์ )
override func viewDidLoad() {
super.viewDidLoad()
collectionView.dataSource = self
collectionView.delegate = self
// ๋ค๋น๊ฒ์ด์
๋ฐ title ๋ฐ๊พธ๊ธฐ
navigationController?.navigationBar.topItem?.title = "๐ Apple Frameworks"
// ...
}
โฟ ๋ ์ฐพ์๋ณผ๊ฒ
Reference
ํจ์คํธ์บ ํผ์ค ์จ๋ผ์ธ ๊ฐ์
'iOS > Toy project' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS : Toy Project] Insta Search View (2) (0) | 2022.05.29 |
---|---|
[iOS : Toy Project] Insta Search View (1) (0) | 2022.05.29 |
[iOS : Toy Project] Apple Framework List (1) (0) | 2022.05.28 |
[iOS: Toy Project] Chat List (0) | 2022.05.23 |
[iOS : Toy Project] Stock Rank (0) | 2022.05.21 |