Skip to content

Instantly share code, notes, and snippets.

@Dev1an
Created December 19, 2019 12:26
Show Gist options
  • Select an option

  • Save Dev1an/f40c370ca424c98a81800bafde9e2837 to your computer and use it in GitHub Desktop.

Select an option

Save Dev1an/f40c370ca424c98a81800bafde9e2837 to your computer and use it in GitHub Desktop.
import SwiftUI
struct FixedHexagon: View {
var body: some view { Hexagon().aspectRatio(2/sqrt(3), contentMode: .fit) }
}
struct Hexagon: Shape {
func path(in rect: CGRect) -> Path {
Path { path in
let width = rect.size.width
let height = rect.size.height
let height4 = height/4
func line(x: CGFloat, y: CGFloat) {
path.addLine(to: CGPoint(x: x, y: y))
}
path.move(to: .zero)
path.addLine(to: CGPoint(x: width/2, y: 0))
path.addLine(to: CGPoint(x: width, y: height4))
path.addLine(to: CGPoint(x: width, y: height4*3))
path.addLine(to: CGPoint(x: width/2, y: height))
path.addLine(to: CGPoint(x: 0, y: height4*3))
path.addLine(to: CGPoint(x: 0, y: height4))
path.addLine(to: CGPoint(x: width/2, y: 0))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment