๐ธchild view
SwiftUI โฉ view โฉ hierarchy โฉ child view
child view (ๅญ่ฆๅ)
่ขซ container view ๆๅ ๅซ็ view๏ผไพๅฆ๏ผ
ContainerView {
childView
}
ใ่ขซ view modifier ไฟฎ้ฃพ็ view๏ผไพๅฆ๏ผ
childView
.modifier()
ไธญ็childView
ใ
root view ่ๅ ถๆๅซ็ๆๆๅญ่ฆๅ (descendants) ๅฝขๆ view hierarchyใ
ๅจ container view ็็ๆณ๏ผๅคงๆฌ่่ฃก้ข็ views ๅฐฑๆฏ child viewsใ
// ่ขซ container view ๆๅ
ๅซ็ view
HStack { // parent
Text("Hello") // child
Color.red // child
}
ๅจๆ view modifiers ็ๆ ๆณไธ๏ผ่ฆๅ้ไพ็๏ผๅ้ข็ๆฏ child view๏ผๅพ้ข็ๆฏ parent viewใ
// ่ขซ view modifier ไฟฎ้ฃพ็ view
view // child
.padding() // parent
.frame(width: 100, height: 100) // grand parent
.border(.black) // grand grand parent
ๅฆๆ็ตๅ่ตทไพ็๏ผ
// container view + view modifiers
HStack { // parent
Text("Hello") // child
Color.red // child
}
.padding() // parent
.frame(width: 100, height: 100) // grand parent
.border(.black) // grand grand parent
้ๆ็ view hierarchy ๅฐฑๆ่ฎๆ๏ผ
// view hierarchy
border โโ frame โโ padding โโ HStack โโฌโ Text
โโ Color.red
Last updated
Was this helpful?