Graphics Programs Reference
In-Depth Information
Views and the View Hierarchy
Views make up the user interface of an application. Each view maintains an image that rep-
resents it. For example, a UIButton 's image is a rounded rectangle with a title in the cen-
ter. A UILabel 's image is just text. When something about a view changes, like a UILa-
bel 's text property or a UIButton 's title , the view's image is redrawn so that these
changes become visible on screen.
Another subclass of UIView is UIWindow . Every application has exactly one instance of
UIWindow that serves as the container for all the views in the application. The window is
created when the application launches. Open HypnosisterAppDelegate.m and find
the application:didFinishLaunchingWithOptions: method.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
In application:didFinishLaunchingWithOptions: , the template added code
that creates a UIWindow object and sends it the message makeKeyAndVisible . This
puts the window on the screen, and once a window is on the screen, you can add other
views to it.
(Note that every iOS application template adds this code. It is not specific to the Empty
Application template. You can see the same code in your QuizAppDelegate.m and
WhereamiAppDelegate.m files, which were created by the Single View Application
template.)
When a view is added to a window, it is said to be a subview of the window. Views that are
subviews of the window can also have subviews, and the result is a hierarchy of view ob-
jects. A view will appear on the screen if and only if its been added to this hierarchy -
either directly as a subview of the window or as a subview of another view that has been
added to the window. Thus, the window is the root of the view hierarchy.
Search WWH ::




Custom Search