Making UIProgressView Rounded corners

前端 未结 13 1687
旧巷少年郎
旧巷少年郎 2021-02-07 13:59

I have created a UIProgressView with following properties

progressView.progressTintColor = UIColor.appChallengeColorWithAlpha(1.0)
progressView.trac         


        
13条回答
  •  深忆病人
    2021-02-07 14:39

    I had this exact same problem, which is what led me to your question after googling like crazy. The problem is two-fold. First, how to make the inside of the progress bar round at the end (which 季亨达's answer shows how to do), and secondly, how to make the round end of the CAShapeLayer you added match up with the square end of the original progress bar underneath (the answer to this other StackOverflow question helped with that How to get the exact point of objects in swift?) If you replace this line of code in 季亨达's answer:

    path.addLine(to: CGPoint(x: self.bounds.width - 5, y: 5))

    with this:

    path.addLine(to: CGPoint(x: (Int(self.progress * Float(self.bounds.width))), y: 5))

    you will hopefully get the result you're looking for.

提交回复
热议问题