In this section, we will learn to draw simple shapes, gradients, or even images. You will need to draw shapes, lines, and images to create custom components or to use in drawing apps where the user can draw shapes and generate an image of their drawing.
When you need to do any custom drawing in iOS, you will need the help of the Core Graphics framework. This framework is full of cool APIs that you can use to build awesome things. In this section, we will see how to use it to sketch custom drawings in custom UIView. In the following demo, we will draw a custom face with eyes, a nose, and a mouth.
Create a new Xcode project with the Single View Application template with name the
Drawing
.Now, let's create a new custom view. Create a new class named
CustomView
, which is a subclass ofUIView
.Add the following function, where custom drawing will be done. Xcode might create it for you, but it will be commented, so...