views:

52

answers:

3

I am just looking at setting up a simple viewController programatically, I have a ViewController.xib file that I have set the background color to RED in interface builder. I have also added the following to my AppDelegate.m

@implementation syntax_MapViewAppDelegate
@synthesize window;

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    viewController = [[MapViewController alloc] init];
    [window addSubview:[viewController view]];
    [window makeKeyAndVisible];
    return YES;
}

-(void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}
@end

When I run the code it does what I expect apart from the white bar at the bottom of the screen, can anyone give me any pointers in how to remove this? I have a feeling I might need to position the view within the window, but I am not sure how?

alt text

cheers Gary

A: 

Something like this might save your problem:

[[viewController view] setFrame:CGRectMake(0, 20, 320, 460)]; 
Vnuce
Here will be larger than screen as you are specifying the height as 480 because we are already taking 20 pixels of top bar into consideration.
Jim
@Jim: you're absolutely correct. It's a mistake make by habit, taking the screen's height as 480. I'm correcting it.
Vnuce
A: 

Set your view to resize dynamically using the autoresizingMask or set it's frame explicitly.

+1  A: 

Please set your view frame.

viewController.view.frame = CGRectMake(0.0,20.0,320.0,460.0);

Now the view cover your full screen with Red color.

You can also set it from interface builder as well.

Jim
Perfect, exactly what I was after. Much appreciated.
fuzzygoat
Just curious, how do you set this from interface builder?
fuzzygoat
If your view size is going to be fixed through out application lifetime then you can set the frame property of view from Interface builder.
Jim