Is a Right-to-Left progress bar possible on iOS?
Asked Answered
S

10

8

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?

Sixtyfourmo answered 23/4, 2011 at 19:17 Comment(2)
You could always create your own progress bar -- it's not hard at all.Incontrovertible
Can we rotate progressbar as Vertical ?Calley
P
11

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;
Pinwheel answered 23/4, 2011 at 19:23 Comment(3)
It works, but the shininess on the bar is now upside-down: can I mirror it vertically as well?Sixtyfourmo
Ah, got it! pv.transform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI), 1.0, -1.0); Thanks!Sixtyfourmo
@Autopulated - That works just fine, or you can use the updated code in my response.Pinwheel
H
9

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.

Haggle answered 23/4, 2011 at 19:26 Comment(0)
S
7

A simpler version is to flip it horizontally.

progressView.transform = CGAffineTransformMakeScale(-1.0f, 1.0f);
Seibel answered 31/3, 2015 at 20:55 Comment(0)
R
5

In iOS 9+, you can use semanticContentAttribute:

progressView.semanticContentAttribute = .forceRightToLeft

Roughish answered 18/5, 2019 at 16:4 Comment(0)
W
3

Swift answer:

progressView.transform = CGAffineTransform(rotationAngle: .pi)
Writ answered 3/3, 2018 at 5:27 Comment(0)
T
2

You can rotate the view by 180°:

progressView.transform = CGAffineTransformMakeRotation(-M_PI);
Tenon answered 23/4, 2011 at 19:26 Comment(0)
A
1

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.

Alps answered 7/12, 2013 at 22:41 Comment(0)
S
1

Swift 5 Version

progressView.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)
Sesame answered 7/2, 2020 at 12:25 Comment(0)
P
1

This works for me using latest SWIFTUI version:

ProgressView(configuration)
.scaleEffect(x: -1, y: 3, anchor: .center)
Ping answered 13/5, 2023 at 15:42 Comment(0)
D
0

SwiftUI solution:

                ProgressView(value: progress)
                    .accentColor(.purple)
                    .frame(alignment: .leading)
                    .rotationEffect(.degrees(180))
Dives answered 15/12, 2023 at 14:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.