Paper tail ----- Quartz2D-draw rich text and images .,
We generally use the drawing provided by UIKit to draw some text and images.
The bottom layer of the method that UIKit provides for us to draw images is also divided into four steps. Therefore, you must write the method in the drawRect method.
1. How to draw text?
Create the text to be painted first
Use the method provided by UIKit to draw.
Method description:
DrawAtPoint: location to which the image is to be painted
WithAttributes: Text style.
[Str drawAtPoint: CGPointZero withAttributes: nil];
2. How to add the drawing text attribute?
Use withAttributes, the last property of the painting method, to set the text attribute.
It requires that a dictionary be passed in. It uses the dictionary key and Value form to set the text style.
Then we can find the key and value in the NSAttributedString class of the UIKit header file.
The usage is as follows:
Create a variable dictionary and set key and value
NSMutableDictionary * dict = [NSMutableDictionary dictionary];
Font
Dict [NSFontAttributeName] = [UIFont systemFontOfSize: 50];
Color
Dict [NSForegroundColorAttributeName] = [UIColor redColor];
Set border color
Dict [NSStrokeColorAttributeName] = [UIColor redColor];
Dict [NSStrokeWidthAttributeName] = @ 1;
Shadow
NSShadow * shadow = [[NSShadow alloc] init];
Shadow. shadowOffset = CGSizeMake (10, 10 );
Shadow. shadowColor = [UIColor greenColor];
Shadow. shadowBlurRadius = 3;
Dict [NSShadowAttributeName] = shadow;
3. What is the difference between drawAtPoint and drawInRect?
DrawAtPoint: cannot automatically wrap
DrawInRect: automatic line feed
4. If you want to draw an image?
To draw an image, you must first import the image material.
AtPoint: Specifies the position to which the image is to be drawn.
Draw by calling the drawAtPoint: CGPointZero method of UIKit;
5. In the process of drawing an image, drawAtPoint: And drawInRect: What are the differences between the two methods?
DrawAtPoint: the size of the drawn image is the same as that of the image.
DrawInRect: the size of the image drawn using this method will be the same as that of the imported rect area.
6. If you want to tile images?
[Image drawAsPatternInRect: rect];
7. How can I use the method provided by UIKit to quickly draw a rectangle?
Quickly fill an area with a rectangle
UIRectFill (rect );
8. How can I use UIKit to crop a region?
UIRectClip (CGRectMake (0, 0, 50, 50 ));
In this method, you must set the cropping area before cropping.