concept draw method in category ios

appears as: draw method, The draw method
iOS Development with Swift

This is an excerpt from Manning's book iOS Development with Swift.

13.3.1. Overriding the draw method

The most common place to draw using Core Graphics is in the draw method of UI-View. This method is called when a view is first laid out and any time that the view needs to be redrawn.

  • Create a subclass of UIView called Star. The draw method shows up in the UIView template, but it’s commented out.
  • Uncomment the draw method:
    class Star: UIView {
        override func draw(_ rect: CGRect) {
            // Drawing code
        }
    }