XIB๋ก ํ ์ด๋ธ๋ทฐ ์ ๋ง๋ค๊ธฐ
ํ ์ด๋ธ๋ทฐ ์ปจํธ๋กค๋ฌ์์ ๋ง๋ค๋ ์ ์ xib๋ก ๋ฐ๋ก ๊บผ๋ด์ ๋ง๋ฆ
์๋ ํ ์ด๋ธ๋ทฐ ์ฝ๋๋ ๋๊ฐ์ด ์งฐ์ง๋ง runtime ์ค๋ฅ๋จ.
guard let ๊ตฌ๋ฌธ์ผ๋ก ๋ฐ๊ฟ์ค ๋ด
guard let ๊ตฌ๋ฌธ์ ์ํด ์๋ฌ ์์ด ๋น ์ ๋ค์ด ๋ค์ด๊ฐ๊ธด ํ์ง๋ง ์ ๋๋ก ์ํ๋ ์ ์ด ์ ๊ฐ์ ธ์์ง.
ํ ์ด๋ธ๋ทฐ ์ ๋ฑ๋กํ๊ธฐ
XIB๋ก ํ ์ด๋ธ๋ทฐ์ ์ ์์ฑํ ๊ฒฝ์ฐ, ํ ์ด๋ธ๋ทฐ์ ์ฌ์ฉํ ์ ์ ๋ฑ๋กํด์ฃผ๋ ๊ณผ์ ์ด ํ์!
- bundle ์ด๋? ์ง๊ธ์ ๋ด ํ๋ก์ ํธ ์์น์ ๋ ๋ผ๊ณ ๋ง ์์๋๊ธฐ.(nil๋ก ํ๋ฉด ๋ด ํ๋ก์ ํธ ์์น)
ํ ์คํธ ์ ๋งํผ ๋์ด ๋ํ๊ธฐ (Dynmic Height)
Dynamic Height์ ์ํด ์ค์ ํด์ผ ํ ๊ฒ
- automaticDimension
- numberOfLines
- Auto Layout(์ฌ๋ฐฑ)
Dynamic height์ ์ฃผ๋ ค๋ฉด ์ ์์ ๋ ์ด์์์ ์ ์ก์์ผํจ.
๋๋น๋ ๋์ด๊ฐ ๊ณ ์ ๋์ ์ ๋์ ์ผ๋ก ๋์ด๋์ง ์๋ ๊ฒฝ์ฐ ๋ฐ์ ํ ์๋ ์์ . (์ฌ๋ฐฑ ์์ฃผ๋ก ๋ ์ด์์ ์ก์์ผํจ)
Swipe - ์ ์์ ๊ตฌํํ ์ ์๋ ๊ธฐ๋ฅ
system ์ ๊ณต Cell ๊ธฐ๋ฅ
- ํธ์ง ( ์ค ๋ณ๊ฒฝ ๋ฑ)
- ์ค์์ดํ (์ญ์ ๋ฑ)
custom ๊ธฐ๋ฅ
System Swipe
์ ์ค์์ดํ ์ญ์ ๊ธฐ๋ฅ ๋ฃ๊ธฐ
- canEditRowAt ๊ตฌํ
์ค์์ดํ ์ญ์ ๋ฒํผ์ ์๊ฒผ์ง๋ง ์ญ์ ๋ ์ ๋จ. ๊ธฐ๋ฅ ๋ฃ์ด์ค์ผํจ
- ์ญ์ ํ ๊ธฐ๋ฅ ๋ฃ์ด์ฃผ๊ธฐ
ํด๋น ์ ์ ์ธ๋ฑ์ค๊ฐ ์ญ์ ์ํ๋ ๋ฐ์ดํฐ ์ธ๋ฑ์ค์ ๊ฐ๊ธฐ ๋๋ฌธ์ ์ indexPath.row ์ด์ฉํด์ remove ํด ์ค
→ ์ค๋ฅ๋จ ๋ฐ์ดํฐ๋ ์ฌ๋ผ์ก๋๋ฐ ๋ทฐ๊ฐ ๊ทธ ์ธ๋ฑ์ค์ ์ ๊ทผํ๋ คํด์
์ค๋ฅ ๊ณผ์
list ๊ธธ์ด 3, tableview ๊ธธ์ด 3
remove 1 (1๋ฒ์ธ๋ฑ์ค ๋ฐ์ดํฐ ์ง์)
list ๊ธธ์ด 2, tableview ๊ธธ์ด 3 (ํ ์ด๋ธ๋ทฐ๊ฐ ์์ด์ง ์ธ๋ฑ์ค ์ ๊ทผํ๋ ค๊ณ ํด์ ์ค๋ฅ๋จ)
ํด๊ฒฐ ๋ฐฉ๋ฒ : ๋ฐ์ดํฐ ์ญ์ ํ ํ ์ด๋ธ ๋ทฐ๋ฅผ ๊ฐฑ์ ํด์ผ ํจ. tableview.reloadData()
Custom Swipe
- ์นด์นด์คํก ์ ์ ์ค์์ดํ ๊ธฐ๋ฅ๋ค(๊ณ ์ ๊ธฐ๋ฅ, ๋ฐฉ๋๊ฐ๊ธฐ , ..)
- ์ง์ ์ปค์คํ ํด์ ์ค์์ดํ ๊ธฐ๋ฅ๊ตฌํ ๊ฐ๋ฅ (๋ค์ํ ๋ฒํผ ๋ชจ์ ๋ฑ )
- leadingSwipeActionsConfigurationForRowAt (์ผ์ชฝ์์ ๋์ค๋ ๋ฒํผ๋ค)
- trailingSwipeActionsConfigurationForRowAt (์ค๋ฅธ์ชฝ์์ ๋์ค๋ ๋ฒํผ๋ค)
์์ ํจ์ ์์ UISwipeActionsConfiguration ๋ง๋ค์ด์ ๊ตฌํ
- ๋ฐฐ์ด์ธ ์ด์ : ์ค์์ดํํด์ ๋์ค๋ ๋ฒํผ์ด ์ฌ๋ฌ๊ฐ ์ผ ์ ์์.
ํ๋ฉด ์ ํ
๊ฐ์ ๋ฒํผ์ผ๋ก ๋ค๋ฅธ ํ๋ฉด๋ค๋ก ์ ํํด์ผ ํ ์ผ์ด ๋ง์์ ์ฝ๋๋ก ๊ตฌํ์ ๋ง์ด ํจ.
๋ํ๊ธฐ ๋ฒํผ ๋๋ฅด๋ฉด ํ๋ฉด ์ ํํ๊ธฐ
๋ค๋น๊ฒ์ด์ ๋ฐ์ bar button item ์ถ๊ฐ
add ์ต์ ์ ํํ๋ฉด ์๋์ผ๋ก ๋ํ๊ธฐ ๋ฒํผ ๋จ
1.์คํ ๋ฆฌ ๋ณด๋ ํ์ผ ์ฐพ๊ธฐ
let vc = DetailViewController()
2.์คํ ๋ฆฌ๋ณด๋ ํ์ผ ๋ด ๋ทฐ์ปจํธ๋กค๋ฌ ์ฐพ๊ธฐ
let sb = UIStoryboard(name: "Main", bundle: nil)
์คํ ๋ฆฌ๋ณด๋ id ์ง์ ํ๋ ๋ฐฉ๋ฒ (ํธ์์ ํด๋์ค ์ด๋ฆ๊ณผ ๊ฐ๊ฒ)
์ด๋ฐ์์ผ๋ก ๊ฐ์ ธ์ค๋ฉด ์คํ ๋ฆฌ๋ณด๋์ ๋ง๋ค์ด ๋์ ๊ทธ๋ฐ๊ฑฐ ํ๋๋ ์์ด ๊ฐ์ ธ์ค๋ ๊ฒ์ด ๋จ.
3. ํ๋ฉด ์ ํ ๋ฐฉ์ ์ค์ (ํจ๊ณผ ์ฃผ๊ธฐ ์ํ ์ต์ ์ฌํญ. ์์ด๋ ํ๋ฉด ์ ํ ๋จ)
vc.modalTransitionStyle = .crossDissolve //๋ชจ๋ฌ ์ ๋๋ฉ์ด์
vc.modalPresentationStyle = .fullScreen //๋ชจ๋ฌ ๋ฐฉ์
fullscreen์ผ๋ก ํ๋ฉด ๋์๊ฐ ๊ธธ์ด ์์ด์ ๋์๊ฐ๋ ๋ฒํผ ๋ง๋ค์ด ์ค์ผ ํจ .
4. ํ๋ฉด ๋์ฐ๊ธฐ
present(vc, animated: true)
modalTransitionStyle
.coverVertical
.crossdisolve
.fliphorizontal
.partialCurl
nav.modalTransitionStyle = .partialCurl //๋ชจ๋ฌ ์ ๋๋ฉ์ด์
nav.modalPresentationStyle = .fullScreen //๋ชจ๋ฌ ๋ฐฉ์
โ ๏ธ .fullScreen์ด๋ ๊ฐ์ด ์จ์ผํจ. ์ ๊ทธ๋ฌ๋ฉด ์ค๋ฅ๋จ.
dismiss ํ ๋๋ animated false๋ก ํด์ค์ผ ํจ.
dismiss(animated: false)
true๋ก ํ๋ฉด ๋ ๋จน์ ์ด์ํจ.
๋ค๋น๊ฒ์ด์ push
navigationController?.pushViewController(vc, animated: true)
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(identifier: "DetailViewController") as! DetailViewController
navigationController?.pushViewController(vc, animated: true)
}
- ์ธํฐํ์ด์ค ๋น๋์ ๋ค๋น๊ฒ์ด์ ์ปจํธ๋กค๋ฌ๊ฐ ์๋ฒ ๋ ๋์ด ์์ด์ผ๋ง Push๊ฐ ๋์! ์๋์ฒ๋ผ initial ๋๋ฉด ์๋ฒ ๋ ์๋ ์
๋ค๋น๊ฒ์ด์ ์ ํธ์ ํ๊ณ ์ถ์ ๋
๋ค๋น๊ฒ์ด์ ์ปจํธ๋กค๋ฌ๊ฐ ์๋ ํํ(์ ๋ชฉ๋ฐ)๋ก Present ํ๊ณ ์ถ์ ๊ฒฝ์ฐ
UINavigationController๋ก ๋ง๋ค์ด์ present
์ด ์ ๋๋ง ์๋ฉด ํ๋ฉด ์ ํ ์ฝ๋๋ ๋ค ์๊ณ ์๋ ์ .
Bar Button Item
์๋์ ๊ฐ์ LeftBarButton, Title๊ณผ dissmis ์ก์ ๊ตฌํ
- style์ 99ํผ์ผํธ ๊ฑฐ์ plain → ์์ ๋กญ๊ฒ ์ปค์คํ ๊ฐ๋ฅ
- target์ 99ํผ์ผํธ ๊ฑฐ์ self
- #selector์ ObjectC์ ์์ฌ special literal๋ผ๊ณ ํจ. ์ต์ ์๊ฑฐ ์ฌ์ฉํ ์ ์๊ฒ ํจ.
- action์๋ IBaction์ฒ๋ผ ์ฝ๋๋ก action ๋ง๋ค์ด์ ๋ฃ์ด์ฃผ๊ธฐ
ํ๋ฉด ์ ๊ฑฐ ํจ์
present → dismiss๋ก ์ ๊ฑฐ
dismiss(animated: true)
push → pop๋ก ์ ๊ฑฐ
navigationController?.popViewController(animated: true)
- popToViewController(): ๋ค์ํ ๋จ๊ณ์ ์ด์ ์ปจํธ๋กค๋ฌ๋ก ๋์๊ฐ ์ ์์
- popViewController(): ํ๋จ๊ณ๋ง ๋์๊ฐ
Toolbar
- ๋ฉ๋ชจ ํ๋จ ๋ฐ or ํค๋ณด๋์ bar๊ฐ ํด๋ฐ
- ์ผ,์๋,์ค ๋ง์ง 0 ์ฃผ๋ฉด ๋์ด์์ด์ ๋ ์ด์์ ๋ฌธ์ ๋ ์ ์๊น
- but ๋ค๋ฅธ ๋ทฐ ์์๊ฐ ์๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ ์ด์์ ์ก์ผ๋ฉด ํ ์ฌ๋ผ๊ฐ๋ฒ๋ฆด ์ ์์
-
- ํด๋ฐ์ bar button item ๋ฃ์ด์ ๋ฒํผ ๊ตฌํํ๋ฉด ๋จ.
- ์๋ ๋๊ฐ๋ ๋ฒํผ ์ฌ์ด์ ๊ณต๊ฐ ๋ํ๋ ์ฉ
Extension
์ด๋ ๋ทฐ์ปจํธ๋กค๋ฌ์์๋ ๊ฐ์ ธ๋ค๊ฐ ์ธ ์ ์์. ๋์ค์ ๋ชจ๋ ์ฑ ์๊น ํ๋ฒ์ ๋ฐ๊พธ๊ธฐ ํธํ ๊ฒ
Tips
๋ทฐ์ปจ ๋ฐฑ๊ทธ๋ผ์ด๋ ์์ ๋ฃ์์ ๋ ํ ์ด๋ธ๋ทฐ๊ฐ ํ์ดํธ๋ผ ๊ฑฐ์ฌ๋ฆผ .
์๋์ฒ๋ผ ํฌ๋ช ์ผ๋ก ํด๋์ผ๋ฉด ์ข์
tableView.backgroundColor = .clear
์ ์๊น ํฌ๋ช ํ๊ฒํ๊ธฐ
cell.backgroundColor = .clear
UIKit ๊ธฐ๋ณธ ํน์ฑ ์ฒ์์ ๋ค ๋ณ๊ฒฝํ๋ ๋ฐฉ๋ฒ
์ผ๊ด ์ ์ฉ ๋จ .
CollectionView
- ์ํ ์คํฌ๋กค์ด ๋๋ค.
- ์ ์ฌ์ด์ฆ๋ฅผ ์กฐ์ ํ ์ ์๋ค.(ํ ์ด๋ธ๋ทฐ์ ์ ๋๋น ๊ณ ์ )
- ๊ธฐ๋ณธ์ ์ผ๋ก ์์ง ์คํฌ๋กค → ์ ๋๋น๊ฐ ๊ธฐ๊ธฐ ๋๋น ๋ฐ์ ๋ณด๋ค ํฌ๋ฉด ์ค๋ณ๋ก ํ๋๋ฐ์ ๋ชป ๋ค์ด๊ฐ์ ์ ๋ ์ด์์ ์ก๋๊ฒ ๊ฐ์ด๋ฐ๋ก ์ด
CollectionView ๊ตฌํ
๊ธฐ๋ณธ ์์ฑ๋์ด์๋ reuseIdentifier ์ญ์
numberOfItemsInSection : ์์ดํ ๊ฐ์
cellForItemAt : ์ ์ค์
register : ์ ๋ฑ๋ก
๋ ์ด์์ ์กฐ์ ํ๊ธฐ
UICollectionViewFlowLayout ์ด์ฉํด์ ์ปฌ๋ ์ ๋ทฐ ๊ตฌํ
sectionInset
minimumLineSpacing
minimumInteritemSpacing
Apple ๊ณต์ ๋ฌธ์ ๊ทธ๋ฆผ
์ผ์ชฝ์์ ์ค๋ฅธ์ชฝ์ผ๋ก ์ ์ด ๋ง๋ค์ด์ง
์ง์ ํด๋์ section inset์ ๋ฌด์กฐ๊ฑด ํ๋ณด ํ ๋ค์ interitemspacing ๊ฐ๊ฒฉ์ ๋บ ํ์ ๋ฐฐ์น ๋จ
์์ดํฐ ๋๋ฐ์ด์ค ๋๋น ๊ฐ์ ธ์ค๋ ์ฝ๋
let width = UIScreen.main.bounds.width
- main์ iOS 16๊น์ง๋ง ์ฐ์.
func setCollectionViewLayout() { let layout = UICollectionViewFlowLayout() let spacing: CGFloat = 20 let width = UIScreen.main.bounds.width - (spacing * 4) layout.itemSize = CGSize(width: width / 3, height: width / 3) layout.sectionInset = UIEdgeInsets(top: spacing, left: spacing, bottom: spacing, right: spacing) layout.minimumLineSpacing = spacing layout.minimumInteritemSpacing = spacing collectionView.collectionViewLayout = layout }
๋ ์ด์์ ์ ์๋๋ฉด Estimate Size : None์ผ๋ก ์ค์
Tip
option๋๋ฅธ์ฑ๋ก ๋๋ฅด๋ฉด ์๋์ ์ฐฝ ์ด๋ฆผ
๋ฐ์ดํฐ ์ ๋ฌ ๊ณผ์
A(VC)→B(VC)
- B์ ๋ณ์(๊ณต๊ฐ) ๋ง๋ จ
- A์์ ๊ฐ ์ ๋ฌ
- B์ ๋ทฐ์ ํํ
- B์ ๋ณ์ ์ถ๊ฐ
- A VC์์ ๋ณ์ ์ ๊ทผ ๊ฐ๋ฅํ๊ฒ ๋จ.
- ๋ฌธ์์ด ๋ฐ์ดํฐ ์ ๋ฌํ๋ฉด์ B VC์์ฑ
- B์ ๋ผ๋ฒจ์ ๋ฐ์ ๊ฐ ๋ฃ๊ธฐ
contentsLabel outlet ์ด ์๊ธฐ๊ธฐ ์ ์ ๊ฐ์ ๋ฃ์ด์ ์ค๋ฅ ์๊ธด ๊ฒ. → ์คํ ๋ฆฌ ๋ณด๋์์๋ ๊ฐ ์ ๋ฌํ ๋ outlet์ ์ฌ์ฉํ ์ ์์. outlet์ด ๋ฆ๊ฒ ์๊น .
ํ๋กํผํฐ ํตํด์ ์ ๋ฌํด์ผํจ.
'SeSAC' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[iOS] TIL_230802 (0) | 2023.08.05 |
---|---|
[iOS] TIL_230801 (0) | 2023.08.03 |
[iOS] TIL_230728 (0) | 2023.08.01 |
[iOS] TIL_230727 (0) | 2023.07.31 |
[iOS] TIL_230726 (0) | 2023.07.31 |