Change Height of UIProgressView in Swift

I faced problem while making the UIProgressView as round rect one. While using only the transform

masteryProgress.transform = CGAffineTransformMakeScale(1, 4)

I achieved which was not my final requirement.

enter image description here

while my final expectation was something like the following

enter image description here

I finally achieved it by following two steps

1. Set Height Constraint from Interface Builder:

enter image description here

2. Create a custom class of UIProgressView and override func layoutSubviews() to add a custom mask layer:

    override func layoutSubviews() {
        super.layoutSubviews()

        let maskLayerPath = UIBezierPath(roundedRect: bounds, cornerRadius: 4.0)
        let maskLayer = CAShapeLayer()
        maskLayer.frame = self.bounds
        maskLayer.path = maskLayerPath.cgPath
        layer.mask = maskLayer
    }

And here is the final result

enter image description here


You can scale it by set its transform like so:

Swift 2

masteryProgress.transform = CGAffineTransformScale(masteryProgress.transform, 1, 20)

Swift 3、4

masteryProgress.transform = masteryProgress.transform.scaledBy(x: 1, y: 20)

enter image description here