본문 바로가기
iOS/예제

[iOS 예제] CircleProgress Shape 만들기

by Sky Titan 2021. 4. 30.
728x90

//
//  ViewController.swift
//  Practice
//
//
import UIKit

class ViewController: ViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //배경 구분
        view.backgroundColor = UIColor.lightGray
        
        //원형 밑그림
        let circlePath = UIBezierPath(arcCenter: view.center, radius: 150, startAngle: 0, endAngle: .pi * 2, clockwise: true)
        circlePath.close()
        
        //track 형태
        let trackLayer = CAShapeLayer()
        trackLayer.path = circlePath.cgPath
        trackLayer.lineWidth = 15
        trackLayer.fillColor = UIColor.clear.cgColor
        trackLayer.strokeColor = UIColor.gray.cgColor
        view.layer.addSublayer(trackLayer)
    
        //progress
        let progressLayer = CAShapeLayer()
        progressLayer.path = circlePath.cgPath
        progressLayer.fillColor = UIColor.clear.cgColor
        progressLayer.lineWidth = 15
        progressLayer.lineCap = .round //progress line stroke 끝을 둥글게
        progressLayer.strokeColor = UIColor.green.cgColor
        progressLayer.strokeStart = 0
        progressLayer.strokeEnd = 0.75 //75%
        view.layer.addSublayer(progressLayer)
    }
  
    
}

 

728x90

댓글