I've just started to make a new app with a navigation bar. I made the first view with the navigation in the AppDelegate.m
.
AppDelegate.m :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
sleep(2);
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
Then, I making the view of the HomeViewController inside loadView
method.
LoadView of HomeViewController :
- (void)loadView
{
self.view = [[UIView alloc] init];
self.view.backgroundColor = [UIColor whiteColor];
self.searchPoiInstructionsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
self.searchPoiInstructionsLabel.layer.borderColor = [UIColor blackColor].CGColor;
self.searchPoiInstructionsLabel.layer.borderWidth = 2.0f;
self.searchPoiInstructionsLabel.text = @"HELLO WORLD";
[self.view addSubview:self.searchPoiInstructionsLabel];
}
My label Hello World doesn't appear...
For the frame, if I set CGRectMake(0, 65, 50, 20)
, 65
for y
, my "Hello World" appears... (I know, I have to increase the width :) )
I just don't understand the origins of my view... If someone can explain me please.
Thanks
This is iOS7 baggage. If you run your app under iOS6, you will see the label as you expect/intend.
Under iOS7, your view originates under the navigation bar which is why you don't see the label when you set the frame to originate at 0,0. If you look really closely, you can actually see the blurred label behind the Carrier indicator in the status bar.
There are multiple ways to work with this:
If the UINavigationBar
is not translucent, then the 0,0 origin will work.
You can update the labels frame using topLayoutGuide
You could use a UIScrollView
instead of UIView