UIProgressView
2 つの画像でカスタマイズするのに苦労しています。インターネットで役立つ質問をたくさん見つけましたが、私の問題は少し異なります。たぶん、私が使用している画像は、角のない長方形で丸くなっています。したがって、stretchableImageWithLeftCapWidth
私の場合、メソッドは役に立たないようです。画像を引き伸ばすと、画像の角が丸くなっているためにスペースができます。このリンクに投稿された質問が1つあります
質問する
5983 次
2 に答える
2
カスタムを実装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のカスタマイズされた値を設定 してください。
于 2013-02-08T15:03:36.107 に答える
1
画像のストレッチに問題がある場合は、サイズ変更を使用してくださいresizableImageWithCapInsets:
UIImage *image = [baseImage resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5) resizingMode:UIImageResizingModeStretch];
于 2013-02-08T15:06:27.450 に答える