15

I have subclassed UIProgressView as:

import UIKit

class MyProgressView: UIProgressView {

    override func sizeThatFits(size: CGSize) -> CGSize {
        return CGSizeMake(size.width, 6)
    }
}

and I am using it as:

let progress = MyProgressView()

progress.progress = 0.33
progress.layer.cornerRadius = 0
progress.tintColor = .white
progress.trackTintColor = UIColor.white.colorWithAlphaComponent(0.4)
navigationItem.titleView = progress

it's working fine, but it has rounded corners like below

progress view with rounded corners

I want it to be non rounded corner. How can I do that?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Byte
  • 629
  • 2
  • 11
  • 29

1 Answers1

38

Simply change the progressViewStyle to UIProgressView.Style.bar, Default is UIProgressView.Style.default.

Swift 3.0 and above

self.progressViewStyle = .bar /* default is .default */

Swift 2.0

self.progressViewStyle = UIProgressViewStyle.Bar
Cœur
  • 37,241
  • 25
  • 195
  • 267
Sahil
  • 9,096
  • 3
  • 25
  • 29
  • you can override init method or can call after creating object of MyProgressView. for e.g let progressView = MyProgressView() progressView.progressViewStyle = UIProgressViewStyle.Bar – Sahil Aug 12 '16 at 12:39
  • 3
    and if you are just creating a subclass for this(for Bar). then you shouldn't create . you can do it by storyboard. – Sahil Aug 12 '16 at 12:56
  • Thanks for suggestion but I am using Xib's – Byte Aug 12 '16 at 13:10