Method 1:
#pragma mark Draw Rectangle Method 1
void DrawRect1 () {
1 Getting the graphics context
Cgcontextref CTX = Uigraphicsgetcurrentcontext ();
2 Draw a line segment
Set a starting point
Cgcontextmovetopoint (CTX, 20, 20);
Cgcontextaddlinetopoint (CTX, 100, 100);
3 Setting the line width
Cgcontextsetlinewidth (CTX, 10);
4 rendering
Cgcontextstrokepath (CTX);
}
Method 2:
#pragma mark Draw Rectangle Method 2
void DrawRect2 () {
1 Getting the graphics context
Cgcontextref CTX = Uigraphicsgetcurrentcontext ();
2 draw Rectangle, add to context first
Cgcontextaddrect (CTX, CGRectMake (10, 10, 50, 50));
3 rendering
Cgcontextstrokepath (CTX);
}
Method 3:
#pragma mark Draw Rectangle Method 3
void DrawRect3 () {
Drawing a rectangle with the Uikit OC method automatically gets the graphics context
Uirectfill (CGRectMake (10, 10, 100, 100));
}
Method 4:
#pragma mark Draw Rectangle Method 4
void DrawRect4 () {
1 Getting the graphics context
Cgcontextref CTX = Uigraphicsgetcurrentcontext ();
Cgcontextstrokerect (CTX, CGRectMake (100, 100, 100, 100));
}
Summary of several methods for drawing rectangles in iOS