Hello,
I want to put a .png image in the middle of the navigation bar instead of the title written in text. Could you please let me know how to do that?
Thanks.
Hello,
I want to put a .png image in the middle of the navigation bar instead of the title written in text. Could you please let me know how to do that?
Thanks.
You can change all the views in a UINavigationBar. If you are trying to alter the navigationBar in a navigation controller do:
self.navigationItem.titleView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"] autorelease];
If you are creating the navigationBar yourself do the same, but in stead of calling self.navigationItem
call: navigationBar.topItem
Set the navigationItem's titleView
UIImage *image = [UIImage imageNamed:@"image.png"];
self.navigationItem.titleView = [[[UIImageView alloc] initWithImage:image] autorelease];
Hello,
I put the image to navigation bar title with the code below, but the image can't fill the all title view. There remains few pixels in right and left sides.
I want to display my image in whole title view area.
Resizing the image doesn't work.
Any ideas?
[self.navController.navigationBar.topItem setTitleView:imageView];
Searching for an answer to this question, I've found a nice and simple solution in the Apple Discussions forum, overriding -(void)drawRect:(CGRect)rect
for UINavigationBar
:
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"NavigationBar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end