Why isn't UIProgressview progress bar resizable?

风流意气都作罢 提交于 2019-12-05 02:39:41

问题


From Bavarious' question about UIProgressViews here:

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?


回答1:


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:

... 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];

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

Looks good to me.



来源:https://stackoverflow.com/questions/10738361/why-isnt-uiprogressview-progress-bar-resizable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!