简体   繁体   English

iOS 上可以使用从右到左的进度条吗?

[英]Is a Right-to-Left progress bar possible on iOS?

I've tried sending [UIProgressView setProgress] negative values, and that doesn't work.我试过发送[UIProgressView setProgress]负值,但这不起作用。

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() ).您可以尝试将UIProgressViewtransform属性设置为一个新的CGAffineTransform ,它将视图旋转 180 度并垂直翻转(以保持“光泽”)(请参阅CGAffineTransformMake()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;

You can rotate the UIProgressView :您可以旋转UIProgressView

progressView.transform = CGAffineTransformMakeRotation(DegreesToRadians(180));

where DegreesToRadians is:其中DegreesToRadians是:

#define DegreesToRadians(d) ((d) * M_PI / 180.0)

To change the progress value, use positive numbers.要更改进度值,请使用正数。

一个更简单的版本是水平翻转它。

progressView.transform = CGAffineTransformMakeScale(-1.0f, 1.0f);

在 iOS 9+ 中,您可以使用semanticContentAttribute

progressView.semanticContentAttribute = .forceRightToLeft

您可以将视图旋转 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.在带有故事板的 iOS 7 中,您可以将 Progress Tint 设置为 Track Tint,反之亦然,然后从 1 中减去常规值并将其设置为当前进度。 Probably better to do it the other (rotation) way, but I thought I would throw this out there.用另一种(旋转)方式可能会更好,但我想我会把它扔在那里。

迅捷回答:

progressView.transform = CGAffineTransform(rotationAngle: .pi)
Swift 5 : progressView.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM