Bartu Bartu - 1 year ago 94
iOS Question

Putting a large logo on UINavigationBar as the title view - iOS

I have successfully added my logo on my navigation bar with this code;

UIImage *image = [UIImage imageNamed: @"top-logo"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];

self.navigationItem.titleView = imageView;

the problem is my logo's height is 54 pixels, where the navigation bar, as defaults has a height of 44 pixels. Logo was intentionally designed to overflow from the bottom of the navigation bar, but I have to change the bounds of navigation bar to do that and I don't want to run over Apple's Guidelines. But I need the imageView which is the titleView of the navigation item to overflow from the navigation bar.

Besides, for one of my apps I reduced the height of navigation bar, which started to act funny when app goes to background and come back (height started to change back to normal, which caused black background within the navigation bar).

Answer Source

Here is a post with a similar situation. The accepted answer used a UIButton instead of an imageview.

Code from accepted answer:

- (void)viewDidLoad {
  [super viewDidLoad];

  UIButton *logoView = [[[UIButton alloc] initWithFrame:CGRectMake(0,0,85,40)] autorelease];
  [logoView setBackgroundImage:[UIImage imageNamed:@"navBarLogo.png"] forState:UIControlStateNormal];
  [logoView setUserInteractionEnabled:NO];

  self.navigationItem.titleView = logoView;

Image instead of title in navigation bar of TTLauncherView

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download