カスタム描画を追加したいビューがあります。
Nib/Xib ファイルに接続されていないビューでこれを行う方法を知っています
- メソッドに描画コードを記述します
-drawRect:
。
しかし、私init
がビューを使用している場合
[[MyView alloc] initWithNibName:@"MyView" bundle:[NSBundle mainBundle]];
-drawRect:
もちろん呼ばれません。以下のコードを実行してみました-viewDidLoad
CGRect rect = [[self view] bounds];
CGContextRef ref = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ref, 2.0);
CGContextSetRGBStrokeColor(ref, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBFillColor(ref, 0, 0, 0, 0);
CGContextAddRect(ref, CGRectMake(1, 1, rect.size.width - 10, rect.size.height - 10));
CGContextStrokePath(ref);
CGContextDrawPath(ref, kCGPathFillStroke);
しかし、何も引かれません。何か案は?