Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ildu

macrumors newbie
Original poster
Feb 12, 2009
5
0
Hi everybody!

I'm very new to xCode and iPhone devving, so excuse my noobism :D.

I'm attempting to use an image to cover the entire navigation bar. The issue is that since I'm using titleView (and navigationItem), it's having problems covering the entire area of the nav bar, scaling the width down from the original size for whatever reason (Fig 1). In the case where I have a navigation bar button, it scales even smaller to make room for the button (Fig 2).

Fig 1: http://img403.imageshack.us/img403/8626/fig1gb3.png
Fig 2: http://img413.imageshack.us/img413/3499/fig2pn3.png

I need the image to cover the entire area of the navigation bar, and somehow get it to go under the nav bar button. The nav bar is initiated inside a tableView controller. Here's my code so far:

Code:
UIImage *image = [UIImage imageNamed:@"navBar.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 0, 320, 44);
self.navigationItem.titleView = imageView;

Is there a better way to do this than using titleView, or can this be remedied somehow without resorting to alternative approaches?
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Is there a better way to do this than using titleView, or can this be remedied somehow without resorting to alternative approaches?
I think you want to avoid using the titleView but instead somehow manipulate the navigationItem or even the navigationBar. You sure you even need a background image for what you're trying to achieve? Wouldn't tintColor suffice?
 

ildu

macrumors newbie
Original poster
Feb 12, 2009
5
0
I got it to work, but a few issues arose.

I took out the titleView command from the tableViewController, and did it the proper way using the navigationController. I added an imageView as a subview to the navigationController. I also shifted the back button init from the tableViewController to follow the image code.

An issue came up:
- The nav bar image now overlaps the back button. I've tried sending it to the back of the stack with sendSubviewToBack, but then it disappears as it apparently goes under the default nav bar. Should I put the button inside another subview and then send it to the front? And how might I do that?

Mi code ('theNavigationController' is my nav controller and 'dataSource' is where the image name is fetched):
Code:
	// set image to navigation bar
	UIImage *navImage = [dataSource navBarImage];
	UIImageView *navImageView = [[UIImageView alloc] initWithImage:navImage];
	[theNavigationController.view addSubview:navImageView];
	
	// create a custom navigation bar button and set it to say the section name
	UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
	backButton.title = [dataSource name];
	theNavigationController.navigationItem.backBarButtonItem = backButton;
	[backButton release];
	
	//[theNavigationController.view sendSubviewToBack:navImageView];

P.S. I do need the nav bar graphics to be images. The image changes with the tab bar selections, so tinting isn't enough for me. In the images that I posted, the actual nav bar image wasn't present, because I want to avoid copyright troubles :D.
 

ildu

macrumors newbie
Original poster
Feb 12, 2009
5
0
No need to put it in another subview. The button already is a subclass of UIView.

Ah, ok. So how do I send the button to the front? Would it then be like this: "[theNavigationController.view sendSubviewToFront:backButton];"?

I don't know if I already tried doing it that way (I don't have a Mac in front of me right now), but it sounds a bit funky since backButton is a navigationItem belonging to theNavigationController, and not necessarily a subview of the controller.
 

ildu

macrumors newbie
Original poster
Feb 12, 2009
5
0
Oops, spoke to soon. It's not. Sorry.

Ah, ok. So any ideas how I should tackle this? As a beginner, I'm not entirely versed in how navigationItems and views are handled together :).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.