IOS Simple to use Uibezierpath drawing

Source: Internet
Author: User

Uibezierpath This class is mainly used for drawing.
The parts of the previous project that needed drawing are drawn with the core graphics, OC is my first language, so the C language API for the core graphics is not very suitable, and recently discovered that the original Apple Uikit has made some simple encapsulation of the core graphics. , Uibezierpath is one of them. Uibezierpath has completely fulfilled some of my basic requirements for drawing.

The benefits of Uibezierpath are obvious.
* First it is the OC language, which is more approachable than the C-language core graphics. * Second it can use arc, if we use cgpathref directly, but also to be responsible for the release at the appropriate time.

Now I will make a simple record according to my own use.

Use

The use of Uibezierpath is quite simple and is divided into three steps:
* Create path * Add route to paths * Draw path

For example, let's draw a line:

Create path    Uibezierpath *path = [Uibezierpath Bezierpath];    Add the path [1 points (100,100) to the line segment of Point (200,100)] to path    [path Movetopoint:cgpointmake];    [Path Addlinetopoint:cgpointmake (+)];    Draw path    [path stroke];

Similarly, we can draw a circle

Uibezierpath *path = [Uibezierpath Bezierpath];    [Path addArcWithCenter:self.center radius:100.0 startangle:0.0 endangle:180.0 Clockwise:yes];    [Path stroke];


In addition to drawing lines and drawing circles, we can also draw a variety of other graphics. You can find the exact method in the Uibezierpath header file, and the use process is basically the same as the core graphics.

There is one place that needs our attention. is the color setting.

The settings for the Uibezierpath color are not included in your own class, but are set directly by Uicolor.
Cases:

Set stroke color    [[Uicolor Bluecolor] setstroke];    Set fill Color    [[Uicolor Redcolor] setfill];

Seems to be the method of uicolor, in fact, also for the cgcontextref of the rendering, and ultimately the role of Cgconextref on the
And Uibezierpath is actually the encapsulation of cgpathref.

So it's not surprising that Uibezierpath can set the color by the Uicolor method.

Because Uicolor and Uibezierpath are ultimately drawn through the core graphics method, only Apple encapsulates a layer of OC.

Finally, with the example of the above circle, add the color and look at the effect.

    Create path    Uibezierpath *path = [Uibezierpath Bezierpath];    Add circle to Path    [path addArcWithCenter:self.center radius:100.0 startangle:0.0 endangle:m_pi*2 Clockwise:yes];    Set the stroke width (to make the stroke look clearer)    [path setlinewidth:5.0];    Set the color (color settings can also be placed on the top, as long as you can before drawing)    [[Uicolor Bluecolor] setstroke];    [[Uicolor Redcolor] setfill];    Strokes and fills    [path stroke];    [Path fill];


Uibezierpath drawing is not quite simple. Of course, the simple use can also have a very good effect, specific you can check the document, there can be a lot of changes oh.

IOS Simple to use Uibezierpath drawing

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.