Build Custom Shapes
Code Your Shape
Create a new file in About Me and give it a name. Then code your shape in SwiftUI.
Estimated time to complete this tutorial:
20 mins
Create a new file in About Me and give it a name. Then code your shape in SwiftUI.
Estimated time to complete this tutorial:
20 mins
Add a new file in About Me. Then create a new shape and give it a name.
Step 1
Open About Me.
Step 2
Open the left sidebar.
Step 3
Tap Add New Item and tap Swift File .
Step 4
Name your file the name of your shape.
Step 5
Begin typing “shape” into the code editor. When code completions appears, tap the arrow or Return on your keyboard to add the set up code for a shape.
Step 6
Give your shape the same name as your file.
Step 7
Delete the code inside the function.
Step 8
Inside the function, create a variable named “path.”
Step 9
Add a few blank lines and return the path at the bottom of the function.
Create your shape using lines.
Step 1
Begin your shape using the move(to:) method and put in the coordinates for where your shape should start. Use the shape you designed to inform your coordinates.
Step 2
Use the addLine(to:) method to add your first line segment.
Step 3
Continue adding line segments to complete your shape.
Step 4
Close your shape using closeSubpath().
Up next: