Making UIProgressView Rounded corners

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

I have created a UIProgressView with following properties

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


        
相关标签:
13条回答
  • 2021-02-07 15:03

    UIProgressView has two part, progress part and track part. If you use Reveal, you can see it only has two subviews. The progress view hierarchy is very simple. so...

    Objective-C

    - (void)layoutSubviews
    {
        [super layoutSubviews];
        [self.progressView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            obj.layer.masksToBounds = YES;
            obj.layer.cornerRadius = kProgressViewHeight / 2.0;
        }];
    }
    

    Swift (3, 4 and 5+)

    override func layoutSubviews() {
        super.layoutSubviews()
        subviews.forEach { subview in
            subview.layer.masksToBounds = true
            subview.layer.cornerRadius = kProgressViewHeight / 2.0
        }
    }
    

    I admit subclass or extend progressView is the recommended way. In case of you don't want to do that for such a simple effect, this may do the trick. Keep the situation that Apple will change the view hierarchy, and something may go wrong in mind.

    0 讨论(0)
提交回复
热议问题