Search code examples
xcode4

Getting a UILabel to appear above a UINavigationBar


self.navigationController.navigationBar.tintColor = [UIColor blackColor];
UILabel *header = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, 320, 10)];
header.text = @"Test";
header.textColor = [UIColor brownColor];
header.backgroundColor = [UIColor clearColor];
header.font = [UIFont fontWithName:@"Zapfino" size: 14.0];
[super viewDidLoad];
[self.view addSubview:header];

This is my code. When I position the UILabel, it won't float over the navigationBar. Is there any way to achieve this?


Solution

  • Add the label as a subview of the navigation bar, not self.view:

    [self.navigationController.navigationBar addSubview:header];