function methods for drawing circles in iOS

Source: Internet
Author: User

-(void) DrawRect: (cgrect) rect

{

CGRect bounds = self.bounds;//based on bounds center point

Cgpoint Center; Center of the centering screen of the center

center.x = bounds.origin.x + bounds.size.width/2.0; Calculate the span of the screen separately, and compare it, since the drawn circle should not exceed the bounds of the screen, with the shorter half as the radius

CENTER.Y = Bounds.origin.y + bounds.size.height/2.0;

float radius = (MIN (bounds.size.height, Bounds.size.width)/2.0);

Uibezierpath *path = [[Uibezierpath alloc]init];//uses the Uibezierpath class to draw the circle, related usage can consult the API documentation, you can remember

[Path Addarcwithcenter:center Radius:radius startangle:0.0 ENDANGLE:M_PI * 2.0 clockwise:yes];//Center point, radius radius, Defines a 0-M_PI * 2.0 radian Path, which is the full circle, clockwise to select Yes or no, because the whole circle is irrelevant

Set the line width to 10

Path.linewidth = 10;

Set Drawing color

[[Uicolor Lightgraycolor] setstroke];

Draw Path

[Path stroke];

}

I am very sorry that I have not typed in the document, because you will encounter problems, after the call, continue to update

function methods for drawing circles in iOS

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.