简体   繁体   English

如何在iOS中创建非圆角UIProgressView

[英]How to create non rounded corner UIProgressView in iOS

I have subclassed UIProgressView as: 我将UIProgressView子类化为:

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 它工作正常,但它有如下角的圆角

带圆角的进度视图

I want it to be non rounded corner. 我希望它是非圆角。 How can I do that? 我怎样才能做到这一点?

Simply change the progressViewStyle to UIProgressView.Style.bar , Default is UIProgressView.Style.default . 只需将progressViewStyle更改为UIProgressView.Style.bar ,默认为UIProgressView.Style.default

Swift 3.0 and above Swift 3.0及以上版本

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

Swift 2.0 Swift 2.0

self.progressViewStyle = UIProgressViewStyle.Bar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM