如何在iOS

时间:2016-08-12 12:27:34

标签: ios swift uiprogressview

我将UIProgressView子类化为:

import UIKit

class MyProgressView: UIProgressView {

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

我将其用作:

let progress = MyProgressView()

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

它工作正常,但它有圆角如下

progress view with rounded corners

我希望它是非圆角。我怎么能这样做?

1 个答案:

答案 0 :(得分:21)

只需将progressViewStyle更改为UIProgressView.Style.bar,默认为UIProgressView.Style.default

Swift 3.0及以上

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

Swift 2.0

self.progressViewStyle = UIProgressViewStyle.Bar