์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- XCTest
- CollectionView
- UIKit
- MVVM
- Xcode
- SwiftUI
- ios
- ๋ฐฑ์ค
- raywenderlich
- BOJ
- rxcocoa
- realm
- Swfit
- TCA
- BFS
- swift
- designpattern
- Kuring
- combine
- reactorkit
- SnapKit
- Lv2
- node.js
- Flutter
- ํ๋ก๊ทธ๋๋จธ์ค
- RxSwift
- visionOS
- tableView
- arkit
- ํจ์คํธ์บ ํผ์ค
Archives
- Today
- Total
lgvv98
[SwiftUI] List (tableView in UIKit) ๋ณธ๋ฌธ
List (tableView in UIKit)
โ SwiftUI์ List์ ๋ํด์ ์์๋ณด์.
List๋ฅผ ๊ตฌ์ฑํ๋๊ฑด ํฌ๊ฒ ์ด๋ ต์ง ์๋ค.
โ MyList
import SwiftUI
struct MyList: View {
// ๋ค๋ฅธ์ชฝ์์ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ฌ ๊ฒ์ด๊ธฐ ๋๋ฌธ์
@Binding var isNavigationBarHidden: Bool
// ๋ฐ์ธ๋ฉ์ ๊ฒฝ์ฐ์๋ ์์ฑ์ ํ์!
init(isNavigationBarHidden: Binding<Bool> = .constant(false)) {
if #available(iOS 14.0, *){
} else {
// ์๋ ๋ฒ์ ์์๋ ํธํฐ๊ฐ ์์ด์ ์ด ์ฝ๋๋ฅผ ํตํด์ ์์ ์ผ ํ๋ค.
UITableView.appearance().tableFooterView = UIView()
}
UITableView.appearance().separatorStyle = .none // ๊ตฌ๋ถ์ ์์ ๊ธฐ
// ๋ด๋ถ์ self.isNavigationBarHidden = isNavigationBarHidden๋ ๊ฐ์ ์๋ฏธ
_isNavigationBarHidden = isNavigationBarHidden
}
var body: some View{
// List{
// Text("๋ง์ด๋ฆฌ์คํธ")
// Text("๋ง์ด๋ฆฌ์คํธ")
// Text("๋ง์ด๋ฆฌ์คํธ")
// Text("๋ง์ด๋ฆฌ์คํธ")
// Text("๋ง์ด๋ฆฌ์คํธ")
// Text("๋ง์ด๋ฆฌ์คํธ")
// }
// List{
// ForEach(1...10, id: \.self){
// Text("๋ง์ด๋ฆฌ์คํธ \($0)")
// }
// }
List{
// ์น์
์ ์ค ์ ์์ด
Section(
// ์น์
์ ํค๋ ์ธํ
header:
Text("์ค๋ ํ ์ผ")
.font(.headline)
.foregroundColor(Color.black)
// ์น์
์ ํธํฐ์ธํ
,footer: Text("footer")
) {
// ํ๋์ ์น์
์ ์์ดํ
3๊ฐ ๋ง๋ฆ
ForEach(1...3, id: \.self){ itemIndex in
MyCard(icon: "book.fill", title: "์ฑ
์ฝ๊ธฐ \(itemIndex)", start: "1 PM", end: "3 PM", bgColor: Color.green)
}
}
// ์น์
์ list์ ๊ฐ row์ inset์ ์ผ๋ง๋ ์ค์ง ์ ํ
.listRowInsets(EdgeInsets.init(top: 10, leading: 10, bottom: 10, trailing: 10))
Section(header:
Text("๋ด์ผ ํ ์ผ")
.font(.headline)
.foregroundColor(Color.black)
) {
ForEach(1...20, id: \.self){ itemIndex in
// ์์ดํ
์ ๋ฐฐ๊ฒฝ์ ์ฌ๊ธฐ์ ์ฒ๋ฆฌ ํด์ผํด!
MyCard(icon: "book.fill", title: "์ฑ
์ฝ๊ธฐ \(itemIndex)", start: "1 PM", end: "3 PM", bgColor: Color.blue)
}
}
.listRowInsets(EdgeInsets.init(top: 10, leading: 10, bottom: 10, trailing: 10))
.listRowBackground(Color.yellow) // ๊ฐ row์ ๋ฐฐ๊ฒฝ์
}
.listStyle(GroupedListStyle()) // ๋ฆฌ์คํธ์ ์คํ์ผ ์ ํ
// .listStyle(PlainListStyle())
.navigationBarTitle("๋ด ๋ชฉ๋ก") // ๋ฆฌ์คํธ์์ ๋ค๋น๊ฒ์ด์
ํ์ดํ ์ฃผ๊ธฐ
// .navigationBarHidden(self.isNavigationBarHidden)
.onAppear { // onAppear๋ ๋ณด์ฌ์ง ๋ ๋ํ๋๋ ์์ฑ
self.isNavigationBarHidden = false // ๋ค๋น๊ฒ์ด์
๋ฐ๊ฐ hidden๋์ง ์๊ฒ๋
}
} // NavigationView
}
โ ContentView
import SwiftUI
struct ContentView: View {
@State var isNavigationBarHidden : Bool = false // contentView์์๋ ๋ค๋น๊ฒ์ด์
๋ฐ๋ฅผ ๊ฐ๋ฆผ
var body: some View {
NavigationLink(
destination: MyList (
isNavigationBarHidden: self.$isNavigationBarHidden // ๋ฌ๋ฌ์ธ์ธ ์ฃผ์
)
) {
Image(systemName: "line.horizontal.3")
.font(.largeTitle)
.foregroundColor(Color.black)
} // NavigationLink
} // body
} // ContentView
์์ ์ฝ๋๋ค์ ์ค๋ช ํ์๋ฉด contentView์์๋ ๋ค๋น๊ฒ์ด์ ๋ฐ๋ฅผ ๊ฐ๋ฆฌ๊ณ ๋ค์ ํ์ด์ง๋ก ๋์ด๊ฐ์ ๋ ํ์ฑํํ๊ธฐ ์ํจ!
'apple > ๐ SwiftUI & Combine' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SwiftUI] GeometryReader (0) | 2022.05.19 |
---|---|
[SwiftUI] NavigationView (0) | 2022.05.18 |
[SwiftUI] Alert (0) | 2022.05.18 |
[SwiftUI] VStack, HStack, ZStack (0) | 2022.05.18 |
[SwiftUI] How to set Image in SwiftUI (0) | 2022.05.18 |
Comments