UIVIewcontroller を使用したストーリーボードのシーンがあります。このシーン内には、背景画像、UIButton、および UIView を含む UIImageview があります。
この UIView には、次のようにオーバーライドされた drawRect メソッドがあります。
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
[self setNeedsDisplay];
CGFloat height = self.bounds.size.height;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
CGContextSetFillColorWithColor(context, [UIColor grayColor].CGColor);
CGFloat barWidth = 30;
int count = 0;
NSArray *values = [NSArray arrayWithObjects:@1, @0.5, nil];
for (NSNumber *num in values) {
CGFloat x = count * (barWidth + 10);
CGRect barRect = CGRectMake(x, height - ([num floatValue] * height), barWidth, [num floatValue] * height);
CGContextAddRect(context, barRect);
count++;
}
CGContextFillPath(context);
}
私の質問は次のとおりです:このカスタムUIViewの背景として画像を設定し、その上に長方形を描画するにはどうすればよいですか?
よろしく