Created
December 19, 2019 12:26
-
-
Save Dev1an/f40c370ca424c98a81800bafde9e2837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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