I. Drawing words
Code:
1 //2 //yytextview.m3 //04-Write text4 //5 //Created by Apple on 14-6-10.6 //Copyright (c) 2014 itcast. All rights reserved.7 //8 9 #import "YYtextview.h"Ten One @implementationYytextview A - -- (void) DrawRect: (cgrect) Rect the { - - //Drawing Text -NSString *str =@"The amount of wind search broke up the pink hair and the two sides of the story offff Wafangdian you f reply F into the membership dues wfh; fly; FN returns WFH; Oh shipment; F reply; Fhisfhsifh my skin is good Apifrhi dividend Awfhiof Wei Feng net i"; + - //1. Get Context + //Cgcontextref CTX = Uigraphicsgetcurrentcontext (); A //2. Drawing at //It is not recommended to use the C method to draw text, because the coordinate system in quraz2d is inconsistent with the coordinate system in the Uikit, the text drawn is reversed, and the C-language method is quite troublesome to draw the text . - //Cgcontextselectfont (< #CGContextRef C#>, < #const char *name#>, < #CGFloat Size#>, < #CGTextEnc Oding textencoding#>) - //Cgcontextshowtext (CTX, < #const char *string#>, < #size_t length#>) - - //Draw a rectangle - //1. Get Context inCgcontextref CTX =Uigraphicsgetcurrentcontext (); - //2. Drawing toCgcontextaddrect (CTX, CGRectMake ( -, -, -, -)); + //3. Rendering - Cgcontextstrokepath (CTX); the * $ //nsmutabledictionary *MD = [nsmutabledictionary dictionary];Panax Notoginseng // //Set Text color - //Md[nsforegroundcolorattributename] =[uicolor Redcolor]; the // //set text background color + //Md[nsbackgroundcolorattributename] = [Uicolor greencolor]; A // //Set Text Size the //Md[nsfontattributename] = [Uifont systemfontofsize:20]; + - //draw text to the point where you are pointing $ //[str drawatpoint:cgpointmake (Ten) WITHATTRIBUTES:MD]; $ - //draws text to a specified range, and does not appear when the text is out of range if the line does not fit automatically -[Str Drawinrect:cgrectmake ( -, -, -, -) Withattributes:nil]; the } - Wuyi the @end
Effect:
Second, the picture
Code Listing 1:
1 //2 //YYIMAGE.M3 //04-Write text4 //5 //Created by Apple on 14-6-10.6 //Copyright (c) 2014 itcast. All rights reserved.7 //8 9 #import "YYimage.h"Ten One @implementationYyimage A - -- (void) DrawRect: (cgrect) Rect the { - - //1. Loading images into memory -UIImage *image = [UIImage imagenamed:@"Me"]; + - + //use the Drawaspatterninrec method to draw the image to layer by tiling the original image A[Image Drawaspatterninrect:cgrectmake (0,0, the,480)]; at } - - - @end
Effect (tiled):
Code Listing 2:
1 #import "YYimage.h"2 3 @implementationYyimage4 5 6- (void) DrawRect: (cgrect) Rect7 {8 9 //1. Loading images into memoryTenUIImage *image = [UIImage imagenamed:@"Me"]; One A - //drawing a picture onto a layer using the OC method - the //use the Drawinrect method to draw the image to layer by stretching the original image -[Image Drawinrect:cgrectmake (0,0, $, $)]; - - //use the Drawaspatterninrec method to draw the image to layer by tiling the original image + //[Image drawaspatterninrect:cgrectmake (0, 0, 480)]; - } + A at @end
Effect (stretch picture):
Code Listing 3:
////YYIMAGE.M//04-Write text////Created by Apple on 14-6-10.//Copyright (c) 2014 itcast. All rights reserved.//#import "YYimage.h"@implementationYyimage- (void) DrawRect: (cgrect) rect{//1. Loading images into memoryUIImage *image = [UIImage imagenamed:@"Me"]; //drawing a picture onto a layer using the OC method//draws a picture to the specified location[Image Drawatpoint:cgpointmake ( -, -)]; }
Effect (draw the picture to a fixed position):
iOS Development UI Chapter-quartz2d simple use (ii)