๐ผ๏ธLine
Last updated
Last updated
SwiftUI โฉ Drawing โฉ Shape โฉ Helper Shapes โฉ
โฌ๏ธ ้่ฆ๏ผ LineShape
// 2022.02.10
import SwiftUI
/// a simple (visible) line relative to a rect.
/// ```
/// let A: UnitPoint = [0.5, 0]
/// let B: UnitPoint = [0, 0.5]
///
/// Line(A, B)
/// Line(A, B, color: .pink)
/// ```
struct Line: View {
let p1: UnitPoint
let p2: UnitPoint
var color: Color = .white.opacity(0.7)
var body: some View {
LineShape(p1: p1, p2: p2).stroke(color) // ๐ LineShape
}
}
// convenience init
extension Line {
init(_ p1: UnitPoint, _ p2: UnitPoint, color: Color = .white.opacity(0.7)) {
self.init(p1: p1, p2: p2, color: color)
}
}
struct Line_Previews: PreviewProvider {
static var previews: some View {
HStack {
Group {
Line([0.5, 0], [0, 0.5])
Line([0.5, 0], [0, 0.5], color: .pink)
Line([0.5, 0], [0, 0.5], color: .blue)
Line([0.5, 0], [0, 0.5], color: .green)
}
.frame(width: 100, height: 100)
.border(Color.white(0.4))
}
}
}
uses (invisible) LineShape.