用圆angular图像定制UIProgressView

我有两个图像自定义UIProgressView困难。 我在互联网上发现了很多有用的问题,但是我的问题有点不一样。 也许在某种程度上,我正在使用的图像是在没有angular的矩形上四舍五入; 因此, stretchableImageWithLeftCapWidth方法似乎没有帮助我的情况。 当我拉伸的图像,由于图像的圆angular有一些空间,有一个问题张贴在这个链接

你将不得不实现自定义UiProgressView并使用下面的代码为您的进度视图,并添加您的图像填充和后台进度视图,在我的情况下,他们是loaderBar.png填充和timeLineBig.png为背景。

CustomProgressView.h

 #import <UIKit/UIKit.h> @interface CustomProgressView : UIProgressView @end 

CustomProgressView.m

 #define fillOffsetX 2 #define fillOffsetTopY 2 #define fillOffsetBottomY 2 #import "CustomProgressView.h" @implementation CustomProgressView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { CGSize backgroundStretchPoints = {10, 10}, fillStretchPoints = {7, 7}; // Initialize the stretchable images. UIImage *background = [[UIImage imageNamed:@"timelineBig.png"] stretchableImageWithLeftCapWidth:backgroundStretchPoints.width topCapHeight:backgroundStretchPoints.height]; UIImage *fill = [[UIImage imageNamed:@"loaderBar.png"] stretchableImageWithLeftCapWidth:fillStretchPoints.width topCapHeight:fillStretchPoints.height]; // Draw the background in the current rect [background drawInRect:rect]; // Compute the max width in pixels for the fill. Max width being how // wide the fill should be at 100% progress. NSInteger maxWidth = rect.size.width - (2 * fillOffsetX); // Compute the width for the current progress value, 0.0 - 1.0 corresponding // to 0% and 100% respectively. NSInteger curWidth = floor([self progress] * maxWidth); // Create the rectangle for our fill image accounting for the position offsets, // 1 in the X direction and 1, 3 on the top and bottom for the Y. CGRect fillRect = CGRectMake(rect.origin.x + fillOffsetX, rect.origin.y + fillOffsetTopY, curWidth, rect.size.height - fillOffsetBottomY); // Draw the fill [fill drawInRect:fillRect]; } @end 

最后当你想使用自定义进度视图,然后调用这样的…

 self.customProgressView=[[CustomProgressView alloc] initWithFrame:CGRectMake(xValue, yValue, widthofProgressView, heightofProgressView)]; 

确保您根据您的要求为xValue,yValue,widthofProgressView和heightofProgressView设置您的自定义值

如果您在扩展图像时遇到问题,请调整resizableImageWithCapInsets:

 UIImage *image = [baseImage resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5) resizingMode:UIImageResizingModeStretch]; 

你可以看看这个链接 。