SwiftUI 绘图

2019-10-18  本文已影响0人  小凡凡520
Path
struct CircleImage: View {
    
    var body: some View {
        Path { path in
            path.move(to: CGPoint(x: 100, y: 100))
            path.addLine(to: CGPoint(x: 200, y: 200))
            path.addLine(to: CGPoint(x: 300, y: 240))
            path.addLine(to: CGPoint(x: 600, y: 740))
        }
        .fill(Color.black)
    }
}

struct CircleImage_Preview: PreviewProvider {
    static var previews: some View {
        CircleImage()
    }
}

struct CircleImage: View {
    
    var body: some View {
        Path { path in
            path.move(to: CGPoint(x: 100, y: 100))
            
            path.addLine(to: CGPoint(x: 200, y: 200))
            
            path.addQuadCurve(
                to: .init(x: 300, y: 240),
                control: .init(x: 30, y: 340))
        }
        .fill(Color.red)
    }
}

struct CircleImage_Preview: PreviewProvider {
    static var previews: some View {
        CircleImage()
    }
}
LinearGradient
struct CircleImage: View {
    
    static let gradientStart = Color(red: 239.0 / 255, green: 120.0 / 255, blue: 221.0 / 255)
    static let gradientEnd = Color(red: 239.0 / 255, green: 172.0 / 255, blue: 120.0 / 255)
    
    var body: some View {
        Path { path in
            path.move(to: CGPoint(x: 20, y: 20))
            
            path.addLine(to: CGPoint(x: 200, y: 20))
            path.addLine(to: CGPoint(x: 200, y: 200))
            path.addLine(to: CGPoint(x: 20, y: 200))
        }
        .fill(
            LinearGradient(
                gradient: Gradient(colors: [CircleImage.gradientStart,CircleImage.gradientEnd]), startPoint: .init(x: 0.5, y: 0),
                endPoint: .init(x: 0.5, y: 0.5))
        )
    }
}

struct CircleImage_Preview: PreviewProvider {
    static var previews: some View {
        CircleImage()
    }
}
struct PageView: View {
    
    var body: some View {
        Rectangle()
            .frame(width: 100, height: 100, alignment: .center)
            .foregroundColor(Color.red)
            .environment(\.colorScheme, .dark)
    }
}

struct PageView_Preview: PreviewProvider {
    
    static var previews: some View {
        PageView()
    }
}

上一篇下一篇

猜你喜欢

热点阅读