Discussion Forums  >  Uncategorized

Replies: 6    Views: 250

SBarnett
Aspiring developer
Profile
Posts: 12
Reg: Jan 18, 2011
Orlando
120
06/20/11 06:37 AM (14 years ago)

Add image/image URL to buttons in Navigation Bar

Hello all! Got another tricky question for you. Have any of you had a need to insert an image, whether an icon or a logo, as one of the buttons in the nav bar? Is there a way to do this? I know I can create a header image and have it be used as navigation but it would be really great if I could have a button on the right side of the nav bar and use an icon or a logo instead of the basic button shape. Is there any way to do that? Steven
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
06/20/11 01:21 PM (14 years ago)
This is a good question. There is, but it's a bit tricky and will require a little magic workaround. Let use the right-side navigation button. a) Create a right-side navigation button on a screen and choose 'organize' for the type of button from the drop down list. This could be any type of button but I'm saying organize because it's not something you're probably using already. b) Set the screen to load when the button is tapped c) Refresh / Test At this point the right button should work. Next, to magically turn it into an image instead of a 'system button' a) Find BT_ViewUtilities > BT_layout.m file in the project. The configureBackgroundAndNavBar method starts on line 215 and it's this method that adds the right side button. b) Find this line: if([rightButtonType isEqualToString:@organize]) ...... The idea is that we are not going to use the standard 'organize button' and instead use an image you added to your project... It will look like this: if([rightButtonType isEqualToString:@organize]) { theBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@yourCustomImage.png] style:UIBarButtonItemStylePlain target:theViewController action:@selector(navRightTap:)]; } All we did is replaced the 'theBarButtonItem' line... re-post if you can't get this figured out.
 
SBarnett
Aspiring developer
Profile
Posts: 12
Reg: Jan 18, 2011
Orlando
120
like
06/20/11 01:44 PM (14 years ago)
This seems fine, but now the ground has fallen out from under me again. I'm having to implement the Tabbed Menu again where I thought I was okay with leaving it out. My issue is that I need it to be somewhat context sensitive. I have two products that get chosen on my home page. What I'd like is to implement the tabbed menu in such a way that if I have these options Home-Videos-FAQs-Resources on the tabs, that they will only bring up the relevant info for the product I've already selected. So, let's say I have Product 1 and Product 2. If I choose Product 1 in my home menu, I'd like the tabbed menu to recognize that I've chosen Product 1 and only navigate to screens appropriate for product 1. Something like: onRowSelect set ProductID=Product1 if RowSelect=1 onRowSelect set ProductID=Product2 if RowSelect=2 Then, let's say you selected Product 1 and touch the Videos tab: if ProductID=Product1 then goto screen 1-8000 Product 1 Videos if ProductID=Product2 then goto screen 2-8000 Product 2 Videos I realize that my code is not real code, but that's now the function I'm looking for. I'm pulling my hair out here as I get a handle on things then I get flipped and now I'm struggling. Any help, as always, is greatly greatly appreciated.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
06/21/11 02:59 PM (14 years ago)
This 'tabbed menu to recognize that I've chosen Product 1 and only navigate to screens appropriate for product 1' is going to be tough. The way I can see it is that you'll need to do two things. First, you'll need your app to keep track of what produce was selected. This variable will need to be global to all other screens. This means you'll need to put this variable in the appDelegate.m file so it's accessable by any other screen. Next, you'll need to somehow identify which screens are associated with the selected product. I'm not sure how you'll do this? It seems to me that you could setup some menus with content associated with each product. Selecting the product loads information for that product. 'Back' then select another product would take you to another menu with info for that product. Tabs aware of this seems like an aweful lot of work?
 
SBarnett
Aspiring developer
Profile
Posts: 12
Reg: Jan 18, 2011
Orlando
120
like
06/24/11 01:10 PM (14 years ago)
Funnily enough, I was able to get this working nearly exactly as you've described before I even saw the reply. I used a UIToolbar with manually inputted CGRect values for Retina/iPhone and iPad. After setting the variable in the appDelegate, I linked the variable to the toolbar method for display only to screens with an id number I ascribed. So the toolbar only displays based on the variable store and the idnumber applicable to that variable. It was tricky. Returning to my earlier post in the thread. I was able to get the image code for the nav bar to work... Partially. The image appears weirdly shrunken and distorted. When using an image for a button, is there an image size/format issue to be aware of? For my toolbar I ended up using icons that were 20x20, i think. This pic I need to use in the upper toolbar has two colors and is a bit rectangular in profile. Steven
 
AppOne
buzztouch Evangelist
Profile
Posts: 348
Reg: Apr 03, 2012
London
13,980
like
10/14/12 05:13 AM (12 years ago)
Accidental post
 
JimmySaver
Aspiring developer
Profile
Posts: 187
Reg: Apr 09, 2012
location unknow...
5,870
like
09/16/13 04:33 AM (11 years ago)
Thought I'd ask here rather than opening a new thread. I'm trying to implement the above one self hosting. My original code is: if([rightButtonType isEqualToString:@"compose"]) theBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:theViewController action:@selector(navRightTap) ]; And I've tried both: if([rightButtonType isEqualToString:@"compose"]) theBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@tweetsheet96x96clear.png] style:UIBarButtonItemStylePlain target:theViewController action:@selector(navRightTap:)]; And if([rightButtonType isEqualToString:@"compose"]) { theBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:tweetsheet96x96clear.png] style:UIBarButtonItemStylePlain target:theViewController action:@selector(navRightTap:)]; } For the first I get an "unexpected @" error and the second gives a "use of undeclared identifier" error for the "tweetsheet96x96clear.png" wording. Any suggestions gratefully received.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.