I've tried sending [UIProgressView setProgress]
negative values, and that doesn't work.
Is there some other way to get a progress bar that fills from the right-hand end?
I've tried sending [UIProgressView setProgress]
negative values, and that doesn't work.
Is there some other way to get a progress bar that fills from the right-hand end?
You could try setting the transform
property of your UIProgressView
to a new CGAffineTransform
that rotates the view by 180 degrees and flips it vertically (to preserve the "shininess") (see CGAffineTransformMake()
and CGAffineTransformRotate()
).
Something along the lines of:
UIProgressView *pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
pv.frame = CGRectMake(10, 100, 300, 11);
CGAffineTransform transform = CGAffineTransformMake(1, 0, 0, -1, 0, pv.frame.size.height); // Flip view vertically
transform = CGAffineTransformRotate(transform, M_PI); //Rotation angle is in radians
pv.transform = transform;
pv.progress = 0.5;
pv.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI), 1.0, -1.0);
Thanks! –
Sixtyfourmo You can rotate the UIProgressView
:
progressView.transform = CGAffineTransformMakeRotation(DegreesToRadians(180));
where DegreesToRadians
is:
#define DegreesToRadians(d) ((d) * M_PI / 180.0)
To change the progress value, use positive numbers.
A simpler version is to flip it horizontally.
progressView.transform = CGAffineTransformMakeScale(-1.0f, 1.0f);
In iOS 9+, you can use semanticContentAttribute
:
progressView.semanticContentAttribute = .forceRightToLeft
Swift answer:
progressView.transform = CGAffineTransform(rotationAngle: .pi)
You can rotate the view by 180°:
progressView.transform = CGAffineTransformMakeRotation(-M_PI);
In iOS 7 with storyboards, you can set the Progress Tint to the Track Tint and vice versa, then subtract the regular value from one and set that to the current progress. Probably better to do it the other (rotation) way, but I thought I would throw this out there.
Swift 5 Version
progressView.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)
This works for me using latest SWIFTUI version:
ProgressView(configuration)
.scaleEffect(x: -1, y: 3, anchor: .center)
SwiftUI solution:
ProgressView(value: progress)
.accentColor(.purple)
.frame(alignment: .leading)
.rotationEffect(.degrees(180))
© 2022 - 2024 — McMap. All rights reserved.