Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Height of UIProgressView in Swift

I've been trying to change the size and rotation of a progress view to adopt the size of the screen. It would basically function have a filling glass effect on the screen of the phone.

I rotated it fairly harmlessly by using self.masteryProgress.transform = CGAffineTransformMakeRotation((CGFloat(-90) / CGFloat(180.0) * CGFloat(M_PI)))

I got the size of the view encasing the screen using view.bounds trying to get the rect and the width x height. So I'm not stuck there.

I tried using .frame .drawRect but when I use those it either breaks them or does nothing.

The height attribute seems to be locked at a constant value of 2 in interfaceBuilder.

Any solutions before I build a custom animation?

I tried setting the height of the progress bar in interfaceBuilder like some other posts said, but I need to have the progress view fill the whole screen no matter what device it's running on so that solution won't work in my case.

I ended up using CGAffineTransformScale(masteryProgress.transform, view.bounds.height / 1334, (view.bounds.width / 2))

Since I'm rotating the progressView vertically, I set the progress view to a width of 1334 (the height of the iPhone 6 Plus) and a height of 2. By dividing the height of the screen by these values it should resize to any phone perfectly.

like image 589
Zach Morris Avatar asked Jul 07 '15 04:07

Zach Morris


1 Answers

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

like image 88
Bannings Avatar answered Oct 22 '22 21:10

Bannings