IOS percent Ring curve swift4.0 implementation

Source: Internet
Author: User

Import UIKit

Class Xzcircleview:uiview {

Let Backgroundlayer = Cashapelayer.init ()///Background white fine curve

Let Progresslayer = Cashapelayer.init ()///progress is really a numerical curve

var Endvale = 0.00

var progresscolor = UIColor.white.cgColor

var backColor = "FFFFFF". Touicolorwithalpha (0.2). Cgcolor

only override Draw () If you perform custom drawing.

An empty implementation adversely affects performance during animation.

Override Func Draw (_ Rect:cgrect) {

Drawing Code

Self.inittheview (Rect)

}

Func Inittheview (_ Rect:cgrect) {

Set the percentage animation display

Set a white background line

Self.backGroundLayer.frame = rect

Self.backGroundLayer.fillColor = UIColor.clear.cgColor

Self.backGroundLayer.lineWidth = 1

Let Backpath = Uibezierpath.init (ArcCenter:CGPoint.init (X:self.p_centerx, Y:self.p_centery), Radius: self.frame.size.width/2.00, Startangle:cgfloat (-DOUBLE.PI * 7.0/6.0), endangle:cgfloat (double.pi/6.0), clockwise: True

Self.backGroundLayer.path = Backpath.cgpath

Self.backGroundLayer.strokeStart = 0

Self.backGroundLayer.strokeEnd = 1

Self.backGroundLayer.strokeColor = BackColor

Self.layer.addSublayer (Self.backgroundlayer)

Self.backGroundLayer.fillColor = UIColor.clear.cgColor

Self.backGroundLayer.lineWidth = 1

Set the real progress curve

Self.progressLayer.frame = rect

Self.progressLayer.fillColor = UIColor.clear.cgColor

Self.progressLayer.lineWidth = 12

Self.progressLayer.lineCap = Kcalinecapround

Let Progresspath = Uibezierpath.init (ArcCenter:CGPoint.init (X:self.p_centerx, Y:self.p_centery), Radius: self.frame.size.width/2.00, Startangle:cgfloat (-DOUBLE.PI * 7.0/6.0), endangle:cgfloat (EndVale), clockwise:true)

Self.progressLayer.path = Progresspath.cgpath

Self.progressLayer.strokeStart = 0

Self.progressLayer.strokeEnd = 1

Self.progressLayer.strokeColor = Progresscolor

Self.layer.addSublayer (Self.progresslayer)

Add animations

Let pathanimation = Cabasicanimation.init (keypath: "Strokeend")

Pathanimation.duration = 0.5

Pathanimation.fromvalue = 0

Pathanimation.tovalue = 1

Pathanimation.timingfunction = Camediatimingfunction.init (name:kcamediatimingfunctioneaseout)

Self.progressLayer.add (Pathanimation, Forkey: "Strokeend")

}

}

IOS percent Ring curve swift4.0 implementation

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.