Here I Have tried to make Rounded Rect corner progress bar but I have some problem to create it, here I have post my code what I am tried?
Any one Give idea to custo
UIProgressView changed position of UIImageView which show current value of progress bar. I have small update to fix this issue
self.layer.cornerRadius = 12
self.clipsToBounds = true
for subview in subviews {
if let imageView = subview as? UIImageView {
imageView.layer.cornerRadius = 12
imageView.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
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
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)
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