I was a bit tired last night but this is another way I meant to send:
//
// PolicyView.swift
// poliAlpha
//
// Created by Ian Brown on 10/17/24.
//
import SwiftUI
struct Polygon: View {
let cornerRad: CGFloat = 12
var body: some View {
VStack {
let polygonWidth: CGFloat = 100
let polygonHeight: CGFloat = 100
let path = Path { path in
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: 0, y: polygonHeight))
path.addLine(to: CGPoint(x: polygonWidth, y: polygonHeight))
path.addLine(to: CGPoint(x: polygonWidth, y: 0))
path.closeSubpath()
}
path.fill()
}
}
}
#Preview {
Polygon()
}
Post
Replies
Boosts
Views
Activity
So, assuming by polygons you mean like a square:
Rectangle()
If you mean like a custom shape, I’d suggest using Vertices.
I’ve linked my repository that deals with this somewhat. I didn’t like Apple’s example in their documentation so I did this instead.
https://github.com/ibapps39/helloTriangle
It’s hard to give you concrete answer because there’s many ways of doing it, from Metal to SceneKit to Swift/SwiftUI‘s various shapes to UIKit, and etc.