OC, oc Language

Source: Internet
Author: User

OC, oc Language

 

Introduction
  • Function

    • Draw
    • Drawing: lines, triangles, rectangles, circles, and Arcs
    • Draw text
    • Draw \ generate image (image)
    • Read \ generate PDF
    • \ Crop an image
    • Custom UI controls (usually controls with complicated internal structures)
    • Most of the controls in UIKit are drawn by the system.
    • Matrix operation (changes all paths shown in the following figure)
    • Zoom
    • Rotate
    • Translation
  • Introduction

    • Z2d belongs to the Core Graphic framework. It is a two-dimensional Drawing Engine that operates directly on layers. It usually obtains the context in-drawRect: method, draw the content to be drawn to the graphic context, then render the layer to the control, and finally close the graphic context.
    • -(Void) drawRect :( CGRect) rect. This method is called only once when the interface is to be displayed. To call this method, call the repainting method-(void) setNeedsDisplay.
Common drawing operations
  • Draw a straight line (three methods)

    • Draw a straight line by adding a path, and then render the context of the path.
    • Enable Context

      • CGContextRef context = UIGraphicsGetCurrentContext ()
    • Description of the path to be drawn

      • Create path
        CGMutablePathRef CGPathCreateMutable (void)
      • Set start point
        Void CGPathMoveToPoint (CGMutablePathRef path, const CGAffineTransform * m, CGFloat x, CGFloat y)
      • Link
        Void CGPathAddLineToPoint (CGMutablePathRef path, const CGAffineTransform * m, CGFloat x, CGFloat y)
    • Add path to context

      • Void CGContextAddPath (CGContextRef context, CGPathRef path)
    • Rendering context

      • Void CGContextStrokePath (CGContextRef c)
    • Draw a straight line directly in the context
    • Enable Context

      • CGContextRef context = UIGraphicsGetCurrentContext ()
    • Description of the path to be drawn

      • Set start point
        Void CGContextMoveToPoint (CGContextRef c, CGFloat x, CGFloat y)
      • Link
        Void CGContextAddLineToPoint (CGContextRef c, CGFloat x, CGFloat y)
    • Rendering context

      • Void CGContextStrokePath (CGContextRef c)
    • Draw a straight line through besell
    • Common besell paths (the most common paths)

      • (UIBezierPath *) bezierPath
    • Set start point

      • (Void) moveToPoint :( CGPoint) point
    • Link

      • (Void) addLineToPoint :( CGPoint) point
    • Rendering

      • (Void) stroke
  • Draw a curve

    • Get Context
    • CGContextRef UIGraphicsGetCurrentContext (void)
    • Draw path
    • Set start point
      Void CGContextMoveToPoint (CGContextRef c, CGFloat x, CGFloat y)
    • Link
      Void CGContextAddQuadCurveToPoint (CGContextRef c, CGFloat cpx, CGFloat cpy, CGFloat x, CGFloat y)
    • Rendering context
      Void CGContextStrokePath (CGContextRef c)
  • Draw an arc (using the besell path)

    • Create besell path
    • + (UIBezierPath *) bezierPathWithArcCenter :( CGPoint) center radius :( CGFloat) radius startAngle :( CGFloat) startAngle endAngle :( CGFloat) endAngle clockwise :( BOOL) clockwise
    • -(Void) stroke
  • Create a pie chart

    • Ideas:
      1) a pie chart is completed by adding two lines to the ARC.
    • Steps
    • Draw an arc using the besell path

      • + (UIBezierPath *) bezierPathWithArcCenter :( CGPoint) center radius :( CGFloat) radius startAngle :( CGFloat) startAngle endAngle :( CGFloat) endAngle clockwise :( BOOL) clockwise
    • Add a straight line to close the path

      • Add a straight line from the path end point to the arc Center
      • -(Void) addLineToPoint :( CGPoint) point
      • The straight line from the path start point to the arc center will be automatically added
        The call-(void) fill method is automatically added
    • Set fill color

      • -(Void) set. This method is used to set the color of the context fill or rendering object.
    • Fill and close the path and render it

      • -(Void) fill, which calls this method through the besell path
  • Draw a bar chart

    • Ideas
      1) The bar chart can be drawn directly through the besell path.
    • Steps
    • Create besell path

      • + (UIBezierPath *) bezierPathWithRect :( CGRect) rect
    • Set fill color

      • -(Void) set. This method is used to set the color of the filling or rendering in the context.
    • Fill and close the path and render it

      • -(Void) fill
  • Draw text

    • Ideas
    • NSString classification NSStringDrawing implements the NSString object painting Method

      • -(Void) drawAtPoint :( CGPoint) point withAttributes :( NSDictionary *) attrs, draw text from a certain point
      • -(Void) drawInRect :( CGRect) rect withAttributes :( NSDictionary *) attrs, draw text in the rect Area
    • When drawing text, you can also set its properties through the attrs Parameter
    • Steps
    • Create an NSString object
    • Set text attributes (the attribute does not exist in a dictionary, and the corresponding attributes are set using the specified key)

      • Set text color
        NSForegroundColorAttributeName
      • Set Font
        NSFontAttributeName
      • Set the rendering width
        NSStrokeWidthAttributeName
      • Set the rendering color
        NSStrokeColorAttributeName
      • Set background attributes
        NSShadowAttributeName
        Set background color: shadowColor (UIColor)
        Fuzzy attribute: shadowBlurRadius (CGFloat)
        Offset: shadowOffset
    • Draw text

      • -(Void) drawInRect :( CGRect) rect withAttributes :( NSDictionary *) attrs
      • -(Void) drawAtPoint :( CGPoint) point withAttributes :( NSDictionary *) attrs. If this method is used, the text is displayed on a single line.
  • Draw Images

    • Ideas
      You can directly call the method of the object that is used to draw the UIImage.
    • Steps
    • Create a UIImage object
    • Create a drawing Area
    • Content set to exceed the drawing area is cut
      UIRectClip (CGRect rect)
    • Draw Images

      • -(Void) drawAsPatternInRect :( CGRect) rect: displays the image in Tiled mode and overwrites the entire rect area)
      • -(Void) drawAtPoint :( CGPoint) point: displays an image of the same size as the original image.
      • -(Void) drawInRect :( CGRect) rect. The image is stretched and the size is equal to rect.
      • -(Void) drawAtPoint :( CGPoint) point blendMode :( CGBlendMode) blendMode alpha :( CGFloat) alpha

--- Restore content end ---

Introduction
  • Function

    • Draw
    • Drawing: lines, triangles, rectangles, circles, and Arcs
    • Draw text
    • Draw \ generate image (image)
    • Read \ generate PDF
    • \ Crop an image
    • Custom UI controls (usually controls with complicated internal structures)
    • Most of the controls in UIKit are drawn by the system.
    • Matrix operation (changes all paths shown in the following figure)
    • Zoom
    • Rotate
    • Translation
  • Introduction

    • Z2d belongs to the Core Graphic framework. It is a two-dimensional Drawing Engine that operates directly on layers. It usually obtains the context in-drawRect: method, draw the content to be drawn to the graphic context, then render the layer to the control, and finally close the graphic context.
    • -(Void) drawRect :( CGRect) rect. This method is called only once when the interface is to be displayed. To call this method, call the repainting method-(void) setNeedsDisplay.
Common drawing operations
  • Draw a straight line (three methods)

    • Draw a straight line by adding a path, and then render the context of the path.
    • Enable Context

      • CGContextRef context = UIGraphicsGetCurrentContext ()
    • Description of the path to be drawn

      • Create path
        CGMutablePathRef CGPathCreateMutable (void)
      • Set start point
        Void CGPathMoveToPoint (CGMutablePathRef path, const CGAffineTransform * m, CGFloat x, CGFloat y)
      • Link
        Void CGPathAddLineToPoint (CGMutablePathRef path, const CGAffineTransform * m, CGFloat x, CGFloat y)
    • Add path to context

      • Void CGContextAddPath (CGContextRef context, CGPathRef path)
    • Rendering context

      • Void CGContextStrokePath (CGContextRef c)
    • Draw a straight line directly in the context
    • Enable Context

      • CGContextRef context = UIGraphicsGetCurrentContext ()
    • Description of the path to be drawn

      • Set start point
        Void CGContextMoveToPoint (CGContextRef c, CGFloat x, CGFloat y)
      • Link
        Void CGContextAddLineToPoint (CGContextRef c, CGFloat x, CGFloat y)
    • Rendering context

      • Void CGContextStrokePath (CGContextRef c)
    • Draw a straight line through besell
    • Common besell paths (the most common paths)

      • (UIBezierPath *) bezierPath
    • Set start point

      • (Void) moveToPoint :( CGPoint) point
    • Link

      • (Void) addLineToPoint :( CGPoint) point
    • Rendering

      • (Void) stroke
  • Draw a curve

    • Get Context
    • CGContextRef UIGraphicsGetCurrentContext (void)
    • Draw path
    • Set start point
      Void CGContextMoveToPoint (CGContextRef c, CGFloat x, CGFloat y)
    • Link
      Void CGContextAddQuadCurveToPoint (CGContextRef c, CGFloat cpx, CGFloat cpy, CGFloat x, CGFloat y)
    • Rendering context
      Void CGContextStrokePath (CGContextRef c)
  • Draw an arc (using the besell path)

    • Create besell path
    • + (UIBezierPath *) bezierPathWithArcCenter :( CGPoint) center radius :( CGFloat) radius startAngle :( CGFloat) startAngle endAngle :( CGFloat) endAngle clockwise :( BOOL) clockwise
    • -(Void) stroke
  • Create a pie chart

    • Ideas:
      1) a pie chart is completed by adding two lines to the ARC.
    • Steps
    • Draw an arc using the besell path

      • + (UIBezierPath *) bezierPathWithArcCenter :( CGPoint) center radius :( CGFloat) radius startAngle :( CGFloat) startAngle endAngle :( CGFloat) endAngle clockwise :( BOOL) clockwise
    • Add a straight line to close the path

      • Add a straight line from the path end point to the arc Center
      • -(Void) addLineToPoint :( CGPoint) point
      • The straight line from the path start point to the arc center will be automatically added
        The call-(void) fill method is automatically added
    • Set fill color

      • -(Void) set. This method is used to set the color of the context fill or rendering object.
    • Fill and close the path and render it

      • -(Void) fill, which calls this method through the besell path
  • Draw a bar chart

    • Ideas
      1) The bar chart can be drawn directly through the besell path.
    • Steps
    • Create besell path

      • + (UIBezierPath *) bezierPathWithRect :( CGRect) rect
    • Set fill color

      • -(Void) set. This method is used to set the color of the filling or rendering in the context.
    • Fill and close the path and render it

      • -(Void) fill
  • Draw text

    • Ideas
    • NSString classification NSStringDrawing implements the NSString object painting Method

      • -(Void) drawAtPoint :( CGPoint) point withAttributes :( NSDictionary *) attrs, draw text from a certain point
      • -(Void) drawInRect :( CGRect) rect withAttributes :( NSDictionary *) attrs, draw text in the rect Area
    • When drawing text, you can also set its properties through the attrs Parameter
    • Steps
    • Create an NSString object
    • Set text attributes (the attribute does not exist in a dictionary, and the corresponding attributes are set using the specified key)

      • Set text color
        NSForegroundColorAttributeName
      • Set Font
        NSFontAttributeName
      • Set the rendering width
        NSStrokeWidthAttributeName
      • Set the rendering color
        NSStrokeColorAttributeName
      • Set background attributes
        NSShadowAttributeName
        Set background color: shadowColor (UIColor)
        Fuzzy attribute: shadowBlurRadius (CGFloat)
        Offset: shadowOffset
    • Draw text

      • -(Void) drawInRect :( CGRect) rect withAttributes :( NSDictionary *) attrs
      • -(Void) drawAtPoint :( CGPoint) point withAttributes :( NSDictionary *) attrs. If this method is used, the text is displayed on a single line.
  • Draw Images

    • Ideas
      You can directly call the method of the object that is used to draw the UIImage.
    • Steps
    • Create a UIImage object
    • Create a drawing Area
    • Content set to exceed the drawing area is cut
      UIRectClip (CGRect rect)
    • Draw Images

      • -(Void) drawAsPatternInRect :( CGRect) rect: displays the image in Tiled mode and overwrites the entire rect area)
      • -(Void) drawAtPoint :( CGPoint) point: displays an image of the same size as the original image.
      • -(Void) drawInRect :( CGRect) rect. The image is stretched and the size is equal to rect.
      • -(Void) drawAtPoint :( CGPoint) point blendMode :( CGBlendMode) blendMode alpha :( CGFloat) alpha

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.