-UIKit에서는 tableview와 같은 것
Identifiable
프로토콜을 채용해야 한다.//name속성을 사용하여 구분
List(items, id: \.name) { item in
Text(item.name)
Text(item.category)
}
//Identifiable 프로토콜 채택
struct AppleProduct: Identifiable, Hashable {
let id = UUID()
let name: String
let summary: String
let category: String
let price: Int
}
Hashable
프로토콜을 요구하는 경우가 많으므로 Identifiable과 함께 사용하는 것이 좋다.List {
Section {
Text("1")
Text("2")
} header: {
Text("Header")
} footer: {
Text("Footer")
}
Text("3")
Text("4")
Text("5")
}
struct CategorizedProduct: Identifiable, Hashable {
let id = UUID()
let header: String
let footer: String?
let list: [AppleProduct]
}
List {
ForEach(items) { section in
Section {
ForEach(section.list) { item in
Text(item.name)
}
} header: {
Text(section.header)
} footer: {
if let footer = section.footer {
Text(footer)
}
}
}
}
List {
...
}
.listStyle(.insetGrouped)
//개별 여백
List {
Section() {
Text("Hello, List!")
Text("List Row Insets")
.listRowInsets(EdgeInsets(top: 0, leading: 60, bottom: 0, trailing: 0))
//전체 여백
List {
Section() {
Text("Hello, List!")
Text("List Row Insets")
Text("List Row Background")
Text("List Row Separator")
Text("List Row Separator Tint")
}
.listRowInsets(EdgeInsets(top: 0, leading: 60, bottom: 0, trailing: 0))
List {
Section() {
Text("Hello, List!")
Text("List Row Insets")
.listRowBackground(Color.yellow)
List {
Section() {
Text("Hello, List!")
Text("List Row Insets")
Text("List Row Background")
Text("List Row Separator")
Text("List Row Separator Tint")
}
.listRowInsets(EdgeInsets(top: 0, leading: 60, bottom: 0, trailing: 0))
.listRowBackground(Color.yellow)
List {
Section() {
Text("Hello, List!")
Text("List Row Insets")
Text("List Row Background")
Text("List Row Separator")
.listRowSeparator(.hidden)
Text("List Row Separator Tint")
}
edges
파라미터를 숨기면 된다..listRowSeparator(.hidden, edges: .bottom)
List {
Section() {
Text("Hello, List!")
Text("List Row Insets")
Text("List Row Background")
Text("List Row Separator")
.listRowSeparator(.hidden, edges: .bottom)
Text("List Row Separator Tint")
}
.listRowInsets(EdgeInsets(top: 0, leading: 60, bottom: 0, trailing: 0))
.listRowBackground(Color.yellow)
.listRowSeparatorTint(.red)
edges
파라미터로 적용 범위 설정 가능Section() {
Text("Custom Header")
} header: {
CustomHeaderView(title: "header", imageName: "star")
}