Hi,
currently I'm doing
self.navigationItem.titleView = [[[UIImageView alloc] initWithImage:image] autorelease];
to set an image in the navigation bar. This way it is centered automatically. Is there any way to have it left aligned ?
Hi,
currently I'm doing
self.navigationItem.titleView = [[[UIImageView alloc] initWithImage:image] autorelease];
to set an image in the navigation bar. This way it is centered automatically. Is there any way to have it left aligned ?
You can make a UIView
as the titleView
, then put the image view as a subview of that UIView
.
Here's how I've done it:
- (void)addLogoLeftButtonBarItem {
UIImage *logoImage = [UIImage imageNamed:@"MyLogo.png"];
if (logoImage == nil) {
NSLog(@"Can't open logo image");
}
UIImageView *logoImageView = [[UIImageView alloc] initWithImage:logoImage];
UIBarButtonItem *logoItem = [[UIBarButtonItem alloc] initWithCustomView:logoImageView];
[self.navigationItem setLeftBarButtonItem:logoItem animated:NO];
[logoItem release];
[logoImageView release];
}
You can also just add the image view as a subview of the navigation bar and postion it wherever you want.