0

I am trying to add a UIProgressView along the top of a UIView. There is a border and rounded corners on the UIView. Currently it looks likes this:

My UIProgressBar and UIView

How can I get the UIProgressBar corners to follow those of the UIView?

The UIProgressView is a subview of the UIView. I have tried setting clipsToBounds = true but it didn't work.

Thanks!

Will Taylor
  • 511
  • 1
  • 6
  • 14

2 Answers2

2

You need to add

yourView.layer.masksToBounds = true

And code will look like:

override func viewWillAppear(_ animated: Bool) {
    mainV.layer.masksToBounds = true
    mainV.layer.borderColor = UIColor.black.cgColor
    mainV.layer.borderWidth = 1.0
    mainV.layer.cornerRadius = 10
}

And result will be:

enter image description here

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
1

You can make progressView rounded by:

self.progressView.layer.cornerRadius = //some int

But clipsToBounds property forces view to not to draw anything outside of the view's bounds.

Check your viewController hierarchy and make sure your progressView is subView of your view not the main view of viewController.

Arash Etemad
  • 1,827
  • 1
  • 13
  • 29