如何在 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
我将 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