views:

112

answers:

3

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 ?

A: 

You can make a UIView as the titleView, then put the image view as a subview of that UIView.

KennyTM
A: 

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];
}
Kristopher Johnson
thanks, perfect !
sph
A: 

You can also just add the image view as a subview of the navigation bar and postion it wherever you want.

Sam