繁体   English   中英

如何在iOS中创建非圆角UIProgressView

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

我将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

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

带圆角的进度视图

我希望它是非圆角。 我怎样才能做到这一点?

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

Swift 3.0及以上版本

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

Swift 2.0

self.progressViewStyle = UIProgressViewStyle.Bar

暂无
暂无

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

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