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).
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
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With