35. Basic SwiftUI Graphics Drawing
The goal of this chapter is to introduce SwiftUI 2D drawing techniques. In addition to a group of built-in shape and gradient drawing options, SwiftUI also allows custom drawing to be performed by creating entirely new views that conform to the Shape and Path protocols.
35.1 Creating the DrawDemo Project
Launch Xcode and select the option to create a new Multiplatform App named DrawDemo.
35.2 SwiftUI Shapes
SwiftUI includes a set of five pre-defined shapes that conform to the Shape protocol which can be used to draw circles, rectangles, rounded rectangles and ellipses. Within the DrawDemo project, open the ContentView.swift file and add a single rectangle:
struct ContentView: View {
var body: some View ...
Get SwiftUI Essentials – iOS 14 Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.