Home > AI > IOS > SwiftUI >

Path

Example 1:

struct SwiftUIView: View {
    var body: some View {
        GeometryReader { geo in
            Line()
        }
        .frame(width: 100, height: 50)
    }
}

struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        SwiftUIView()
    }
}


struct Line: View {
    let geoProx = MyGeometryProxy()
 
    var body: some View {
 
        Path{ path in
            path.move(to: CGPoint(x: geoProx.size.width/2, y: geoProx.size.height/2))
            path.addLine(to: CGPoint(x: geoProx.size.width/2 - geoProx.size.width/4, y: geoProx.size.height/2))
 
        }
        .stroke(style: StrokeStyle(lineWidth: 8.0, lineCap: .round))
        .foregroundColor(.blue)
        .zIndex(1.5)
    }
}
 
 
struct MyGeometryProxy {
    var size = MySize()
     
    struct MySize {
        var width: CGFloat = 300
        var height: CGFloat  = 300
    }
}



struct MyGeometryProxy {
    var size = MySize()
    
    struct MySize {
        var width: CGFloat = 300
        var height: CGFloat  = 300
    }
}

Example 2:

struct Line: View {

    var body: some View {
        
        Path { path in
            path.move(to: CGPoint(x: 200, y: 100))
            path.addLine(to: CGPoint(x: 100, y: 300))
            path.addLine(to: CGPoint(x: 300, y: 300))
            path.addLine(to: CGPoint(x: 200, y: 100))
        }
        .stroke(style: StrokeStyle(lineWidth: 8.0, lineCap: .round))
        .foregroundColor(.blue)
        .zIndex(1.5)
        
    }
}

Leave a Reply