【问题标题】:UIProgressView custom progress bar with UIImageUIProgressView 用 UIImage 自定义进度条
【发布时间】:2012-06-20 23:52:13
【问题描述】:

我使用的是 iOS 5,我一直在搜索,但没有找到是否可以使用 UIProgressView 和 UIImage 制作粗进度条。如何使用一个小的 .png 文件并基本上使用 UIProgressView 将其拉伸,使其看起来像一个进度条,或者有可能吗?是否有可能使那个 .png 高,或者它会被限制在 UIProgressView 有多高?提前感谢您的帮助!

【问题讨论】:

    标签: uiimage resize progress-bar uiprogressview


    【解决方案1】:

    我已经找到了怎么做。首先在 iPhone 屏幕上放一个 UIProgressView。我把我的放在 x:86 y:272。我将它连接到视图控制器的 .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);
    

    这会获取图像并从中间拉伸它,同时保留每一侧的像素。但是,必须使用图像编辑器更改图像的宽度。我认为不可能拉伸宽度。

    progBar.png: 轨道栏.png:

    【讨论】:

      猜你喜欢
      • 2019-07-21
      • 2014-02-27
      • 2014-01-29
      • 1970-01-01
      • 2014-04-14
      • 2011-08-10
      • 2010-10-29
      • 2016-05-06
      • 2015-12-16
      相关资源
      最近更新 更多