contentView
カスタム コントロールと 1 つのカスタムコントロールを含むウィンドウをプログラムで作成しようとしていますが、NSTextField
このウィンドウとビューの階層を自分自身で描画するのに問題があります。
カスタムのボーダレス ウィンドウを作成し、そのsetContentView
/contentView
アクセサーをオーバーライドします。これは正常に機能しているようで、カスタムの contentViewinitWithFrame
とdrawRect
メソッドが呼び出され、contentView が正しく描画されます。
NSTextField
しかし、プログラムでカスタムを追加しようとするとすぐに、contentView
追加または描画されません。カスタムとは、指定されたイニシャライザ ( initWithFrame:frame
- カスタム フォント設定のみ) と次のような drawRect メソッドをオーバーライドすることを意味します。
- (void)drawRect:(NSRect)rect {
NSRect bounds = [self bounds];
[super drawRect:bounds];
}
カスタム contentView の初期化子は次のようになります。
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self != nil) {
// i want to draw itself to the same
// size as contentView thus i'm using same frame
CustomTextField *textField = [[CustomTextField alloc] initWithFrame:frame];
[self addSubview:textField];
[self setNeedsDisplay:YES];
}
return self;
}
私はこれに数時間苦労してきたので、どんな指針も大歓迎です。リクエストに応じて、より多くのコードを入手できます。)