UIView をサブクラス化し、詳細ビュー コントローラーを介して呼び出しています。ロードすると、正しい寸法と配置で表示されますが、それは単なる黒い四角です... UIView をクラスのインターフェイスビルダーに入れるだけで機能します。draw rect が呼び出されるとは思わない。私のコードは次のとおりです。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setNeedsDisplay];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 255.0, 255.0, 0, 1);
CGContextStrokeRect(context, CGRectMake(0, 0, 50, 50));
}
そして私はそれを次のように呼びます:
GameBox *boxy = [[GameBox alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];
[self.view addSubview: boxy];