ios-Bezier Curve

Source: Internet
Author: User

Git:[email Protected]:lu459700780/uibezierpath.git

Demonstrate:

#import "ViewController.h"@interfaceViewcontroller () @property (nonatomic,assign) BOOL Plus_minus; @property (nonatomic,strong) Cashapelayer*Shapelayer, @property (nonatomic,strong) Uibezierpath*Trackpath, @property (nonatomic,strong) Cashapelayer*Tracklayer, @property (nonatomic,strong) Uibezierpath*Progresspath, @property (nonatomic,strong) Cashapelayer*Progresslayer, @property (nonatomic,strong) Nstimer*timer; @property (nonatomic,strong) Cashapelayer*Shapelayert, @property (nonatomic,strong) Cashapelayer*Shapelayertm;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; _plus_minus=YES; //Create CashapelayerSelf.shapelayer =[Cashapelayer layer]; Self.shapeLayer.frame= CGRectMake ( -, -, -, -);//self.shapeLayer.position = self.view.center;Self.shapeLayer.fillColor = [Uicolor Cyancolor]. Cgcolor;//fill Color is Clearcolor//set the width and color of a lineSelf.shapeLayer.lineWidth =1.0f; Self.shapeLayer.strokeColor=[Uicolor Redcolor].    Cgcolor; //Create a circular Bezier curveUibezierpath * Circlepath = [Uibezierpath bezierpathwithovalinrect:cgrectmake ( -, -, -, -)]; //make Bezier curves associated with CashapelayerSelf.shapeLayer.path =Circlepath.cgpath; //one, add and display draw a circle//[Self.view.layer AddSublayer:self.shapeLayer];        /*Stroke : With the meaning of the stroke here is the starting pen and the end of the pen position of 1 words is a full circle, 0.5 is half a circle, 0.25 is 1/4 laps. etc.*/Self.shapeLayer.strokeStart=0; Self.shapeLayer.strokeEnd=0.75; //two, draw two circle, one of the circle represents the progress[Self Createbezierpath:cgrectmake ( -, $, -, -)]; //third, create a rotating circle[self circlebezierpath]; //Iv. make a five edge by dot draw line[self fiveanimation]; //Five, draw a dashed line[self createdottedline]; //Six, draw an arc[self createcurvedline];}-(void) createcurvedline{Uibezierpath* Apath =[Uibezierpath Bezierpath]; Apath.linewidth=5.0; Apath.linecapstyle= Kcglinecapround;//Line CornersApath.linejoinstyle = Kcglinecapround;//Endpoint Processing[Apath Movetopoint:cgpointmake ( -, -)]; [Apath Addquadcurvetopoint:cgpointmake ( -, -) Controlpoint:cgpointmake ( -,0)]; Cashapelayer* curvedlinelayer=[Cashapelayer layer]; Curvedlinelayer.path=Apath.cgpath; [Self.view.layer Addsublayer:curvedlinelayer];}-(void) createdottedline{Cashapelayer*shapelayer =[Cashapelayer layer];    [Shapelayer SetBounds:self.view.bounds];    [Shapelayer SetPosition:self.view.center];        [Shapelayer Setfillcolor:[[uicolor Clearcolor] cgcolor]; //set the dashed line color to Blackcolor[Shapelayer setstrokecolor:[[uicolor colorwithred:223/255.0Green223/255.0Blue223/255.0Alpha1.0f] [Cgcolor]]; //3.0f Set the width of the dashed line[Shapelayer setlinewidth:1.0f];        [Shapelayer Setlinejoin:kcalinejoinround]; //3 = width of the line 1 = spacing per line[Shapelayer setlinedashpattern: [Nsarray arraywithobjects:[nsnumber Numberwithint:3], [nsnumber numberwithint:1],nil]]; //Setup the pathCgmutablepathref Path =cgpathcreatemutable (); Cgpathmovetopoint (Path, NULL,0, the); Cgpathaddlinetopoint (Path, NULL, the, the);    [Shapelayer Setpath:path];        Cgpathrelease (path); //You can change self to any uiview you want, and the demo is put into the UITableViewCell.[[Self.view layer] addsublayer:shapelayer];}//five-angle shape-(void) fiveanimation{Uibezierpath*apath =[Uibezierpath Bezierpath]; //start point from top left down to right point[Apath Movetopoint:cgpointmake ( -, -)]; //Dash Point[Apath Addlinetopoint:cgpointmake ( -, $)]; [Apath Addlinetopoint:cgpointmake ( -, -)]; [Apath Addlinetopoint:cgpointmake ( the, -)]; [Apath Addlinetopoint:cgpointmake ( the, $)];    [Apath Closepath]; //set point is a 5*5 small circle (self-added)Uibezierpath *path = [Uibezierpath bezierpathwithovalinrect:cgrectmake ( --5/2.0, -, -, -)];        [Apath Appendpath:path]; Cashapelayer*shapelayer =[Cashapelayer layer]; //Set Border colorShapelayer.strokecolor =[[Uicolor Redcolor]cgcolor]; //set the fill color if only the side can set the inside [Uicolor Clearcolor]Shapelayer.fillcolor =[[Uicolor Bluecolor]cgcolor]; //It is this sentence that is associated with each other (Uibezierpath and Cashapelayer):Shapelayer.path =Apath.cgpath; [Self.view.layer Addsublayer:shapelayer];}-(void) circlebezierpath{_timer= [Nstimer scheduledtimerwithtimeinterval:0.15target:self selector: @selector (circleanimationtypeone) Userinfo:nil Repeats:yes]; Self.shapelayert=[Cashapelayer layer]; Self.shapeLayerT.frame= CGRectMake (0,0, Max, Max); Self.shapeLayerT.position=Self.view.center; Self.shapeLayerT.fillColor=[Uicolor Clearcolor].        Cgcolor; //set the width and color of a lineSelf.shapeLayerT.lineWidth =2.0f; Self.shapeLayerT.strokeColor=[Uicolor Redcolor].    Cgcolor; //set the stroke start pointSelf.shapeLayerT.strokeStart =0; Self.shapeLayerT.strokeEnd=0; //Create a circular Bezier curveUibezierpath * Circlepath = [Uibezierpath bezierpathwithovalinrect:cgrectmake (0,0, Max, Max)]; //make Bezier curves associated with CashapelayerSelf.shapeLayerT.path =Circlepath.cgpath; //Add and display[Self.view.layer AddSublayer:self.shapeLayerT]; Self.shapelayertm=[Cashapelayer layer]; Self.shapeLayerTM.frame= CGRectMake (0,0, the, the); Self.shapeLayerTM.position=Self.view.center; Self.shapeLayerTM.fillColor=[Uicolor Clearcolor].        Cgcolor; //set the width and color of a lineSelf.shapeLayerTM.lineWidth =2.0f; Self.shapeLayerTM.strokeColor=[Uicolor Bluecolor].        Cgcolor; //set the stroke start pointSelf.shapeLayerTM.strokeStart =0; Self.shapeLayerTM.strokeEnd=0; //Create a circular Bezier curveUibezierpath * circlepathtm = [Uibezierpath bezierpathwithovalinrect:cgrectmake (0,0, the, the)]; //make Bezier curves associated with CashapelayerSelf.shapeLayerTM.path =Circlepathtm.cgpath; //Add and display[Self.view.layer AddSublayer:self.shapeLayerTM];}-(void) circleanimationtypeone{NSLog (@"strokestart===%f", Self.shapeLayerT.strokeStart); NSLog (@"strokeend====%f", self.shapeLayerT.strokeEnd); if(Self.shapeLayerT.strokeEnd >1&& Self.shapeLayerT.strokeStart <1) {Self.shapeLayerT.strokeStart+=0.1; Self.shapeLayerTM.strokeStart+=0.1; }Else if(Self.shapeLayerT.strokeStart = =0) {self.shapeLayerT.strokeEnd+=0.1; Self.shapeLayerTM.strokeEnd+=0.1; }        if(Self.shapeLayerT.strokeEnd = =0) {Self.shapeLayerT.strokeStart=0; Self.shapeLayerTM.strokeStart=0; }    if(Self.shapeLayerT.strokeStart = =self.shapeLayerT.strokeEnd) {self.shapeLayerT.strokeEnd=0; Self.shapeLayerTM.strokeEnd=0; }    }//Draw two Circles-(void) Createbezierpath: (cgrect) mybound{//Outer Circle_trackpath = [Uibezierpath bezierPathWithArcCenter:self.view.center radius: (mybound.size.width-0.7)/2StartAngle:0endangle:m_pi*2Clockwise:yes]; _tracklayer= [CashapelayerNew];    [Self.view.layer Addsublayer:_tracklayer]; _tracklayer.fillcolor=Nil; _tracklayer.strokecolor=[Uicolor Graycolor].    Cgcolor; _tracklayer.path=_trackpath.cgpath; _tracklayer.linewidth=5; _tracklayer.frame=Mybound; //Inner Circle_progresspath = [Uibezierpath bezierPathWithArcCenter:self.view.center radius: (mybound.size.width-0.7)/2Startangle:-m_pi_2 Endangle: (m_pi*2)*0.7Clockwise:yes]; _progresslayer= [CashapelayerNew];    [Self.view.layer Addsublayer:_progresslayer]; _progresslayer.fillcolor=Nil; _progresslayer.strokecolor=[Uicolor Redcolor].    Cgcolor; _progresslayer.linecap=Kcalinecapround; _progresslayer.path=_progresspath.cgpath; _progresslayer.linewidth=5; _progresslayer.frame=Mybound; }@end

ios-Bezier Curve

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.