为什么 UIProgressview 进度条不能调整大小? [英] Why isn't UIProgressview progress bar resizable?

查看:61
本文介绍了为什么 UIProgressview 进度条不能调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自巴伐利亚关于的问题">此处为 UIProgressViews:

我尝试实现 Dave DeLong 所说的,并且我按照他在示例中展示的方式完成了所有操作,但是当我运行该程序时,如果我尝试更改进度值,我的进度条会变成一个拉伸的图像.然而,轨道图像完美地调整大小并沿轨道重复.出于某种原因,进度不会沿着进度条执行此操作.

I tried implementing what Dave DeLong said and I did everything the exact way he showed in his example, but when I run the program, my progress bar becomes a stretched image if I try changing the value of the progress. The track image however resizes perfectly and repeats along the track. For some reason, the progress isn't doing this along the progress bar.

UIImage * load = [[UIImage imagedNamed:@"load.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 1, 0, 1)];
UIImage * track = [[UIImage imageNamed:@"track.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 1, 0, 1)]; 
[progressbar progressImage:load];
[progressbar trackImage:track];
[progressbar setProgress:0.5];

我尝试将我的图像变量从进度图像切换到轨道图像,以查看是否是无法调整大小的图像(它不应该是因为它们是完全相同的图像,只是颜色不同).除了当我这样做时,轨道图像再次完美地调整大小,进度图像是拉伸的图像.有谁知道为什么会发生这种情况?

I tried switching my image variables from the progress image to the track image to see if maybe it was the image that wasn't resizable (which it shouldn't have been because they were the exact same image, just different colors). Except when I did this, the track image again resized perfectly and the progress image was the one that stretched. Does anyone know why this may be happening?

推荐答案

你的可调整大小的大写插图可能不应该是 {0,1,0,1}.在您的情况下,它们看起来应该是 {0,0,0,0}UIEdgeInsetsZero.

Your resizable cap insets probably shouldn't be {0,1,0,1}. In your case, it looks like they should be {0,0,0,0}, or UIEdgeInsetsZero.

我剪掉了红色和蓝色的小方块:

I clipped out the little red and blue squares:

... 然后将它们放入 UIProgressView:

... and then threw them into a UIProgressView:

UIImage *red = [[UIImage imageNamed:@"red"] resizableImageWithCapInsets:UIEdgeInsetsZero];
UIImage *blue = [[UIImage imageNamed:@"blue"] resizableImageWithCapInsets:UIEdgeInsetsZero];

[pv setTrackImage:blue];
[pv setProgressImage:red];

当进度视图以 progress 为 0.5 放置在 UI 上时,我得到了这个:

When the progress view was placed on the UI with a progress of 0.5, I got this:

我觉得不错.

这篇关于为什么 UIProgressview 进度条不能调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆