【问题标题】:How to create non rounded corner UIProgressView in iOS如何在 iOS 中创建非圆角 UIProgressView
【发布时间】:2016-08-12 12:27:33
【问题描述】:

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

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

我希望它是非圆角。我该怎么做?

【问题讨论】:

    标签: ios swift uiprogressview


    【解决方案1】:

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

    Swift 3.0 及以上版本

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

    Swift 2.0

    self.progressViewStyle = UIProgressViewStyle.Bar
    

    【讨论】:

    • 你可以重写init方法,也可以在创建MyProgressView的对象后调用。例如让 progressView = MyProgressView() progressView.progressViewStyle = UIProgressViewStyle.Bar
    • 如果您只是为此创建一个子类(对于 Bar)。那么你不应该创建 .你可以通过故事板来做。
    • 感谢您的建议,但我正在使用 Xib 的
    猜你喜欢
    • 2014-12-02
    • 2021-11-17
    • 1970-01-01
    • 2016-12-31
    • 2018-07-14
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    • 2019-10-02
    相关资源
    最近更新 更多