๐WidthDimension
Last updated
Last updated
โฌ๏ธ ้่ฆ๏ผ LeftArrow
struct WidthDimension: View {
// view properties
var label: Color = .primary
var arrow: Color = .secondary
// view body
var body: some View {
// โญ๏ธ ไฝฟ็จ GeometryReader ไพ่ฎๅใๅฏฌๅบฆใ
GeometryReader { geo in
let width = geo.size.width
HStack{
// ๐ LeftArrow
LeftArrow(color: arrow)
// dimension
Text("\(width, specifier: "%.0f")") // โญ๏ธ no decimal places
.font(.system(size: 14)).bold()
.foregroundColor(label)
.fixedSize() // โญ๏ธ no wrap
// ๐ LeftArrow
LeftArrow(color: arrow)
.scaleEffect(-1, anchor: .center) // โญ๏ธ turn around
}
}.frame(height: 25) // โญ๏ธโญ๏ธโญ๏ธ ้่ฃกๆๅฎ้ซๅบฆๅพ้่ฆโ๏ธ
} // ไธ็ถ GeometryReader ๆไฝๆปฟๆดๅ็ฉบ้๏ผ
} // ้ ๆๅค็ไฝฟ็จ overlay ๆๅฐ้ฝ็กๆโ๏ธ
uses LeftArrow to draw width dimension.
rotated to make HeightDimension.
used by .dimension() to put a width dimension beside a view.
Thinking in SwiftUI โฉ Ch.4 Layout โฉ Grid Views โญ๏ธ