Looking back at the blog you wrote, the cat decided to change the style later
The original intention is to see the effect of direct copy code can be used, complete annotation is also convenient to learn, but found that this is particularly difficult for beginners to learn, the source of material will not be uploaded, there is want to go to the group to find.
After the style is basically –> look at the title –> look at the directory –> see the picture –> see the code –> own try.
Of course, if there is a good for the demo cat will be the same as the original put up.
Cat Share, must boutique
Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243?viewmode=contents
Drawing text
Effect:
Code:
////NYTEXTVIEW.M//Draw pictures to draw text////Created by Apple on 15-5-5.//Copyright (c) 2015 Znycat. All rights reserved.//#import "NYTextView.h" @implementation nytextview - (ID) initWithFrame: (CGRect) frame{ Self= [SuperInitwithframe:frame];if( Self) {//initialization code}return Self;} - (void) DrawRect: (CGRect) rect{//Draw text NSString*STR = @cat meow,!?? Cat meow,!?? Cat meow,!?? Cat meow,!?? ";//1. Get Context //Cgcontextref CTX = Uigraphicsgetcurrentcontext (); //2. Drawing The C method is not recommended for drawing text because the coordinate system in the quraz2d is inconsistent with the coordinate systems in the Uikit, the drawn text is reversed, and the C-language method is quite troublesome to draw the text . //Cgcontextselectfont (< #CGContextRef C#>, < #const char *name#>, < #CGFloat Size#>, < #CGTextEn Coding textencoding#>) //Cgcontextshowtext (CTX, < #const char *string#>, < #size_t length#>) //Draw Rectangle //1. Get ContextCgcontextref CTX = Uigraphicsgetcurrentcontext ();//2. DrawingCgcontextaddrect (CTX, CGRectMake (Ten,Ten, the, the));//3. RenderingCgcontextstrokepath (CTX);//Nsmutabledictionary *MD = [nsmutabledictionary dictionary]; //// Set text color //Md[nsforegroundcolorattributename] =[uicolor Redcolor]; //// Set text background color //Md[nsbackgroundcolorattributename] = [Uicolor greencolor]; //// set Text size //Md[nsfontattributename] = [Uifont systemfontofsize:20]; //Draw text to the point where you are pointing //[str drawatpoint:cgpointmake (Ten) WITHATTRIBUTES:MD]; //Draws text to the specified range, and wraps automatically if one line does not fit, and does not appear when the text is out of range[Str Drawinrect:cgrectmake ( -, -, the, the) Withattributes:Nil];}@end
Painting Pictures Tile Pictures
////NYIMAGEVIEW.M//Draw pictures to draw text////Created by Apple on 15-5-5.//Copyright (c) 2015 Znycat. All rights reserved.//#import "NYImageView.h" @implementation nyimageview - (ID) initWithFrame: (CGRect) frame{ Self= [SuperInitwithframe:frame];if( Self) {//initialization code}return Self;} - (void) DrawRect: (CGRect) rect{//1. Loading images into memory UIImage*image = [UIImageimagenamed:@"Cat"];//Use the Drawaspatterninrec method to draw the image to layer by tiling the original image[Image Drawaspatterninrect:cgrectmake (0,0, the,480)];}@end
Stretch picture
Effect:
Code:
////NYIMAGEVIEW.M//Draw pictures to draw text////Created by Apple on 15-5-5.//Copyright (c) 2015 Znycat. All rights reserved.//#import "NYImageView.h" @implementation nyimageview - (ID) initWithFrame: (CGRect) frame{ Self= [SuperInitwithframe:frame];if( Self) {//initialization code}return Self;} - (void) DrawRect: (CGRect) rect{//1. Loading images into memory UIImage*image = [UIImageimagenamed:@"Cat"];//Use the OC method to draw the picture onto the layer //Use the Drawinrect method to draw the image to layer by stretching the original image[Image Drawinrect:cgrectmake (0,0,260,260)];}@end
Picture fixed position
Effect:
Code:
////NYIMAGEVIEW.M//Draw pictures to draw text////Created by Apple on 15-5-5.//Copyright (c) 2015 Znycat. All rights reserved.//#import "NYImageView.h" @implementation nyimageview - (ID) initWithFrame: (CGRect) frame{ Self= [SuperInitwithframe:frame];if( Self) {//initialization code}return Self;} - (void) DrawRect: (CGRect) rect{//1. Loading images into memory UIImage*image = [UIImageimagenamed:@"Cat"];//Use the OC method to draw the picture onto the layer //Draw the picture to the specified location[Image Drawatpoint:cgpointmake ( -, -)];}@end
Cat learning iOS (30) UI quartz2d picture Drawing text