You don't need to override the This method if your view sets it content in other ways.
By the time this method is called, UIKit have configured the drawing environment appropriately for your view and you can Si Mply call whatever drawing methods and functions your need to render your content. Specifically, UIKit creates and configures a graphics context for drawing and adjusts the transform of that-context so tha T its origin matches the origin of your view ' s bounds rectangle. You can get a reference to the graphics context using the Uigraphicsgetcurrentcontext function, but does not establish a str Ong reference to the graphics context because it can change between calls to the Drawrect:method.
This method was called when a view was first displayed or when an event occurs that invalidates a visible part of the VI ew. You should never call this method directly yourself. To invalidate part of your view, and thus cause, portion to being redrawn, call the Setneedsdisplay or SETNEEDSDISPLAYINR Ect:method instead.
The above is an official Apple document.
IOS Drewrect method