iOS uses core graphics and Uibezierpath painting

Source: Internet
Author: User

The UIView-(void) DrawRect: (cgrect) Rect function can be re-painted on the view with the sub-class.

Re-painting can be done through the core graphics and Uibezierpath.

1. Painting with the core graphics function

The first step is to get the current drawing context through the Uigraphicsgetcurrentcontex () function.

Then set the starting point, increase the line to a point,,,, close, for example:

    //gets the current paint contextCgcontextref context=Uigraphicsgetcurrentcontext (); //sets the starting point of the painting, and if the part to be drawn exceeds the bounding frame of the current drawing context, the excess is clippedCgcontextmovetopoint (Context,- -, -Ten); //Add a line to point 100,200Cgcontextaddlinetopoint (Context, -, $); Cgcontextaddlinetopoint (Context,0, $); //closing line to beginningCgcontextclosepath (context); //here is the stroke, here can not be missing, otherwise the painting does not work, the previous operation looks more like the following to prepare for the drawing, only the following step is executed to succeedCgcontextstrokepath (context);

2.nsstirng,uiimage, you can draw directly in the current context
    UIImage * Card = [UIImage imagenamed:@ "cardback"];    [Card Drawatpoint:cgpointmake (-ten,-ten)];    [@ "Hello cgcontext" drawatpoint:cgpointmake (ten) Withattributes:nil];

3.UIBezierPath painting
    Uibezierpath * Path = [[Uibezierpath alloc] init];    [Path Movetopoint:cgpointmake (ten)];    [Path Addlinetopoint:cgpointmake];    [Path Addlinetopoint:cgpointmake];    [Path Closepath];     // here is the stroke, here can not be missing, otherwise the painting does not work, the previous operation looks more like the following to prepare for the drawing, only the following step is executed to succeed    [Path stroke];

Uibezierpath and the core graphics function are drawn almost, except that they can be drawn directly without the current context, and are generally drawn using Uibezierpath.

The core graphics function is only used when Uibezierpath cannot be implemented.

iOS uses core graphics and Uibezierpath painting

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.