I'm trying to programmatically create a window with custom contentView
and one custom NSTextField
control, but i'm having trouble getting this hierarchy of window and views to draw themselves.
I create a custom borderless window and override it's setContentView
/ contentView
accessors. This seems to work fine and custom contentView's initWithFrame
and drawRect
methods get called causing contentView to draw itself correctly.
But as soon as i try programmatically adding custom NSTextField
to contentView
it doesn't get added or drawn. By saying custom i mean that i override it's designated initializer (initWithFrame:frame
- only for custom font setting) and drawRect method which looks like this:
- (void)drawRect:(NSRect)rect {
NSRect bounds = [self bounds];
[super drawRect:bounds];
}
The custom contentView's initializer looks like this:
- (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;
}
I've been strugling with this for few hours so any pointers are much appreciated. More code is available on request .)