简体   繁体   English

自定义 UIProgressView

[英]Custom UIProgressView

I'm using a UIProgressView in my application, which is working great right now.我在我的应用程序中使用了UIProgressView ,它现在工作得很好。 But I want to make it larger (height-wise) and color it a different color.但我想让它更大(高度)并将其着色为不同的颜色。

I'm looking to use PDColoredProgressView for the color, and alter the -(void)drawRect:(CGRect)rect method to change the height, however I can't decide where I would actually alter the height.我希望使用PDColoredProgressView作为颜色,并更改-(void)drawRect:(CGRect)rect方法来更改高度,但是我无法决定实际更改高度的位置。 Any suggestions on what to change?关于改变什么的任何建议?

所以事实证明你可以像任何其他视图一样调整它的大小。

[coloredProgressView setFrame:CGRectMake(0, 0, 300, 25)];

Setting the frame side didn't seem to work for me.设置框架侧似乎对我不起作用。 Setting the transform to a CGAffineTransformMakeScale() can scale it up - not sure if that causes any other problems though.将转换设置为 CGAffineTransformMakeScale() 可以将其放大 - 不确定这是否会导致任何其他问题。

To change the height of progressView try below code: ( works with Swift 5 )要更改 progressView 的高度,请尝试以下代码:(适用于 Swift 5)

progressView.transform = CGAffineTransform(scaleX: 1, y: 4) // y present the wanted height progressView.transform = CGAffineTransform(scaleX: 1, y: 4) // y 表示想要的高度

and 1 present the current width, so if you change it to 3 then it will mean current width x 2和 1 表示当前宽度,因此如果将其更改为 3,则表示当前宽度 x 2

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

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