How to create non rounded corner UIProgressView in iOS

て烟熏妆下的殇ゞ 提交于 2019-12-08 17:00:57

问题


I have subclassed UIProgressView as:

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?


回答1:


Simply change the progressViewStyle to UIProgressView.Style.bar, Default is UIProgressView.Style.default.

Swift 3.0 and above

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

Swift 2.0

self.progressViewStyle = UIProgressViewStyle.Bar


来源:https://stackoverflow.com/questions/38917974/how-to-create-non-rounded-corner-uiprogressview-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!