У меня возникли трудности с настройкой UIProgressView
с двумя изображениями. Я нашел много полезных вопросов в Интернете, но моя проблема немного отличается. Возможно, так, что изображения, которые я использую, закруглены по неугольным прямоугольникам; поэтому, stretchableImageWithLeftCapWidth
метод, похоже, не помогает в моем случае. Когда я растягиваю изображения, есть пробел из-за закругленных углов изображений, на этот вопрос отправлен один вопрос. linkИндивидуальный UIProgressView с закругленными углами изображения
2
A
ответ
2
Вам необходимо будет внести изменения в Custom 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 в соответствии с вашими требованиями
1
Если возникли проблемы растягивание использование изображения размер resizableImageWithCapInsets:
UIImage *image = [baseImage resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5) resizingMode:UIImageResizingModeStretch];
Спасибо за ответ, я дам ему попытку и вернусь к вам, если я столкнусь с проблемами – sam46
представляется полезным, но все равно нужно исправление в изображениях по высоте и ширине, я думаю, но, похоже, мне придется договориться это, соответственно, как вы сказали в своем ответе, спасибо миллиону – sam46
сделано и работает! – sam46