サブクラス化して独自のカスタムUIProgressViewを作成し、drawRect関数を上書きしようとしています。進行状況入力バーを除いて、すべてが期待どおりに機能します。高さと画像が正しくわかりません。
画像は両方ともRetina解像度であり、シミュレーターはRetinaモードです。画像の名前は「progressBar@2x.png」(高さ28px)および「progressBarTrack@2x.png」(高さ32px)です。
CustomProgressView.h
#import <UIKit/UIKit.h>
@interface CustomProgressView : UIProgressView
@end
CustomProgressView.m
#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
{
// Drawing code
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, 16);
UIImage *progressBarTrack = [[UIImage imageNamed:@"progressBarTrack"] resizableImageWithCapInsets:UIEdgeInsetsZero];
UIImage *progressBar = [[UIImage imageNamed:@"progressBar"] resizableImageWithCapInsets:UIEdgeInsetsMake(4, 4, 5, 4)];
[progressBarTrack drawInRect:rect];
NSInteger maximumWidth = rect.size.width - 2;
NSInteger currentWidth = floor([self progress] * maximumWidth);
CGRect fillRect = CGRectMake(rect.origin.x + 1, rect.origin.y + 1, currentWidth, 14);
[progressBar drawInRect:fillRect];
}
@end
結果のProgressViewは、適切な高さと幅を持ちます。また、適切な割合で埋められます(現在は80%に設定されています)。ただし、進行状況の塗りつぶし画像は正しく描画されません。
誰かが私がどこで間違っているのかわかりますか?