uiimage - UIProgressView 使用 UIImage 自定义进度条

标签 uiimage resize progress-bar uiprogressview

我使用的是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: progBar.png 轨迹栏.png: trackBar.png

关于uiimage - UIProgressView 使用 UIImage 自定义进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11129777/

相关文章:

ios - NSValueTransformer 如何工作?

ios - 为表格 View 单元格图像创建圆形图片

Android ProgressBar .xml 布局

ios - 单元格的进度条在其他单元格上重复

swift - 下载并保存 PFFile (UIImage) 以在 UIImageView 中显示 : SWIFT

google-chrome - 调整表格中图像的大小仅适用于 chrome

jquery - 调整大小时更新 jQuery 函数中的值

html - 如何更改输入文件按钮大小?

ios - 显示微调器事件,直到加载音频文件 IOS7

swift - 如何截取屏幕的一部分