Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 383
Bartu Avatar asked Jan 13 '13 19:01

Bartu


2 Answers

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

like image 136
propstm Avatar answered Oct 27 '22 20:10

propstm


First, in your -viewDidLoad method, create an UIImageView that fits the NavigationBar size. After that you put your logo inside that UIImageView and set it to be your titleView. The code is below:

UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,40,40)];
image.contentMode = UIViewContentModeScaleAspectFit;
[image setImage: [UIImage imageNamed:@"logo"]];
self.navigationItem.titleView = image;
like image 23
Maurício Fonseca Avatar answered Oct 27 '22 18:10

Maurício Fonseca