我使用的是iOS 5,我一直在搜索,但没有找到是否可以使用 UIProgressView 和 UIImage 制作一个厚进度条。如何使用一个小的 .png 文件并基本上使用 UIProgressView 拉伸(stretch)它,使其看起来像进度条或者是否可能?是否可以使 .png 变高,或者是否会限制 UIProgressView 的高度?预先感谢您的帮助!
最佳答案
我已经知道怎么做了。首先在iPhone屏幕上放置一个UIProgressView。我把我的放在 x:86 y:272 处。我将它连接到 View Controller 的 .h 文件,将其命名为 progView,并在 .m 文件中 @synthesized 它。我将以下代码放入 ViewDidLoad 方法中:
// Select the images to use
UIImage *track = [[UIImage imageNamed:@"trackBar"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)];
UIImage *progress = [[UIImage imageNamed:@"progBar"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)];
// Set the track and progress images
[self.progView setTrackImage:track];
[self.progView setProgressImage:progress];
[self.progView setProgressViewStyle:UIProgressViewStyleDefault]; // we don't need anything fancy
// Create a bound where you want your image. This places the attached .png bars so that the bar drains downward. I was using this as a countdown bar on the iPhone.
self.progView.frame = CGRectMake(-70, 70, self.view.bounds.size.height/1.00, 100);
// A normal progress bar fills up from left to right. I rotate it so that the bar drains down.
self.progView.transform = CGAffineTransformMakeRotation((90) * M_PI / 180.0);
这会获取图像并从中间拉伸(stretch)它,保留每一侧的像素。但必须使用图像编辑器更改图像的宽度。我认为不可能拉伸(stretch)宽度。
progBar.png: 轨迹栏.png:
关于uiimage - UIProgressView 使用 UIImage 自定义进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11129777/