Paper tail ----- Quartz2D-draw rich text and images .,

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.