Making UIProgressView Rounded corners

前端 未结 13 1675
旧巷少年郎
旧巷少年郎 2021-02-07 13:59

I have created a UIProgressView with following properties

progressView.progressTintColor = UIColor.appChallengeColorWithAlpha(1.0)
progressView.trac         


        
13条回答
  •  闹比i
    闹比i (楼主)
    2021-02-07 14:47

    Another answer to throw in the mix, super hacky but very quick to use.

    You can just grab the sublayer and set its radius. No need to write your own UIProgressView or mess with clip paths.

    progressView.layer.cornerRadius = 5
    progressView.layer.sublayers[1].cornerRadius = 5
    progressView.subviews[1]. clipsToBounds = true
    progressView.layer.masksToBounds = true
    

    So you round the corner of your overall UIProgressView (no need for ClipsToBounds) Then the fill bar is the 2nd sublayer, so you can grab that and round its Corners, but you also need to set the subview for that layer to clipsToBounds.

    Then set the overall layer to mask to its bounds and it all looks good.

    Obviously, this is massively reliant on the setup of UIProgressView not changing and the 2nd subview/layer being the fill view.

    But. If you're happy with that assumption, super easy code wise to use.

提交回复
热议问题