Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create non rounded corner UIProgressView in iOS

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?

like image 603
Byte Avatar asked Aug 12 '16 12:08

Byte


1 Answers

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
like image 136
Sahil Avatar answered Nov 15 '22 10:11

Sahil