How to make rounded corner progress bar in swift?

In which it tells you to set the corner radius and then clip to bounds: (The sublayers is so the inside bar has rounded corners as well.) soo add these lines because you need to set both the progress color and his layer also...

 progressBar.layer.cornerRadius = 8
 progressBar.clipsToBounds = true
 progressBar.layer.sublayers![1].cornerRadius = 8
 progressBar.subviews[1].clipsToBounds = true

Although you have set the corner radius, you also need to tell the view not to draw anything outside of the view's bounds by setting

self.progressView.clipsToBounds = true

Swift 5.0

//Extension to set corner any view  set border width and color. 
extension UIView{
    func setCorner(withRadius:Int, borderWidth:Int = 0, color: UIColor = .clear){
        self.layer.cornerRadius = radius
        self.layer.borderColor = color
        self.layer.borderWidth = borderWidth
        self.clipsToBounds = true
    }
}

use it as

self.progressView.setCorner(withRadius: 12)

And if you want to have rounded edges for the inner bar too, you can also add this code:

// Set the rounded edge for the outer bar
self.layer.cornerRadius = 12
self.clipsToBounds = true

// Set the rounded edge for the inner bar        
self.layer.sublayers![1].cornerRadius = 12
self.subviews[1].clipsToBounds = true

Tags:

Swift