๐น.frame()
Last updated
Last updated
TestFrameView - demo ideal size, min width.
TestIdealSizeView - test ideal size behaviors.
TestLittleSquares - demo adaptive layout.
.frame() ๅชๆฏๆน่ฎ parent's proposed size๏ผไธฆ้ๆน่ฎ child view's size๏ผchild view ๆฌ่บซ็ๅคงๅฐ้ๆฏ็ฑ child view ่ชๅทฑๆฑบๅฎโ๏ธ(๐ See: TestFrameView)
a view may behave differently on each axis.
Spacer inside a VStack will probably take all space vertically, but no space horizontally.
There are cases (e.g. Text) when the behavior in one axis will be affected by the other.
pull-in views: only take as much space as needed, e.g. HStack/VStack.
adaptive pull-in views: take only what they need, if offered is not enough, they'll do their best (truncate or wrap) to respect the offered space, e.g. Text.
push-out views: take all the space offered, e.g. Rectangle.
Custom views: draw outside the area offered.
.padding( )๏ผๆๆน่ฎ frameโ
can use .testFrame() to test frame behaviors.
convenience extensions: view + .frame()
can use .dimension() (View extension) to show a view's frame visually.
ๅ๏ผๅฆไฝ่ฃฝไฝไธๅๅ Text ไธๆจฃ็ custom view๏ผๅฏไปฅๆ นๆ parent's offered size๏ผ่ชฟๆดๆ็ท่ฒผ่ชๅทฑๅ งๅฎน็ frameโ