quartz2d simple Use (ii)
I. Drawing words
Code:
8 9 #import "YYtextview.h" @implementation YYtextview12-(void) DrawRect: (CGRect) rect15 {16 17//Draw Text NSString *str = @ "The amount of wind search broke up the pink hair and the two sides of the Offff-wa-fang you f reply F into the membership dues wfh; fly; f reply; Wfh My skin good fhisfhsifh dividend Apifrhi Wei Feng net i"; 19 2 0//1. Get context//Cgcontextref CTX = Uigraphicsgetcurrentcontext (); 22//2. Drawing 23//The C method is not recommended for drawing text because Q The coordinate system in the uraz2d is inconsistent with the coordinate system in the Uikit, the text that is drawn is reversed, and the method of drawing the text by means of the C language is quite troublesome//Cgcontextselectfont (< #CGContextRef c#>, <# const char *name#>, < #CGFloat Size#>, < #CGTextEncoding textencoding#>)//Cgcontextshowtext (CTX, & lt; #const Char *string#>, < #size_t length#>) 26 27//Draw Rectangle 28//1. Get context Cgcontextref CTX = Uigra Phicsgetcurrentcontext (); 30//2. Draw Cgcontextaddrect (CTX, CGRectMake (50, 50, 100, 100)); 32//3. Render the CGC Ontextstrokepath (CTX); nsmutabledictionary *md = [nsmutabledictionary dictionary];37////Set text color //Md[nsforegroundColorattributename] =[uicolor redcolor];39////Set text background color//md[nsbackgroundcolorattributename] = [Uicolor greenCo LOR];41////Set Text size//md[nsfontattributename] = [Uifont systemfontofsize:20];43 44//Draw text to the pointing position 45 [Str drawatpoint:cgpointmake (+) withattributes:md];46 47//draws text to a specified range, if one line does not fit automatically, when the text is out of range Do not display [str drawinrect:cgrectmake (withattributes:nil];49, +, +)}50 @end
Effect:
Second, the picture
Code Listing 1:
8 9 #import "YYimage.h" @implementation YYimage12-(void) DrawRect: (CGRect) rect15 {+ // 1. Load image into memory UIImage *image = [UIImage imagenamed:@ "Me"];19 // Use the Drawaspatterninrec method to draw the image to layer, by tiling the original picture [image drawaspatterninrect:cgrectmake (0, 0, 320, 480)];23}24 25 26 @end
Effect (tiled):
Code Listing 2:
1 #import "YYimage.h" 2 3 @implementation yyimage 4 5 6-(void) DrawRect: (cgrect) rect 7 {8 9 // 1. Load image into memory UIImage *image = [UIImage imagenamed:@ "Me"];11 //Use OC method to draw pictures onto layer 15 //Use the Drawinrect method to draw the image to layer by stretching the original image [Image drawinrect:cgrectmake (0, 0, 19,];17) //Use Drawaspatterninrec method to draw the image to layer, is by tiling the original image// [Image drawaspatterninrect:cgrectmake (0, 0, 480)];20}21 @end
Effect (stretch picture):
Code Listing 3:
8 9 #import "YYimage.h" @implementation YYimage12-(void) DrawRect: (CGRect) rect15 {//< c21/>1. Loading pictures into memory UIImage *image = [UIImage imagenamed:@ "Me"];19 //Using OC method to draw pictures onto layer 22 //Draw the picture to the specified location [image Drawatpoint:cgpointmake (+)];25 }
Effect (draw the picture to a fixed position):
quartz2d simple Use (ii)