␡
- The View Hierarchy
- Getting a View to Draw Itself
- Drawing with NSBezierPath
- NSScrollView
- Creating Views Programmatically
- For the More Curious: Cells
- For the More Curious: isFlipped
- Challenge
This chapter is from the book
Creating Views Programmatically
You will instantiate most of your views in Interface Builder. Every once in a while, you will need to create views programmatically. For example, assume that you have a pointer to a window and want to put a button on it. This code would create a button and put it on the window's content view:
NSView *superview = [window contentView]; NSRect frame = NSMakeRect(10, 10, 200, 100); NSButton *button = [[NSButton alloc] initWithFrame:frame]; [button setTitle:@"Click me!"]; [superview addSubview:button]; [button release];