Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 63

Crown Solutions
Aspiring developer
Profile
Posts: 463
Reg: Nov 11, 2011
MN
13,480
08/15/12 07:46 PM (11 years ago)

Using an image as a back button

Has anyone done this? I am looking at this code in the BT_ViewUtilities.m and from what I understand, I need to insert a UIimage rather then call the localized string? i figured out how to change the text, but I need to use the image in this case. My lack of JSON knowledge is kicking my ass... }else{ if([theViewController respondsToSelector:@selector(navLeftTap)]){ NSString *backText = NSLocalizedString(@"Back",@"Back"); if(![[BT_strings getJsonPropertyValue:theScreenData.jsonVars:@"navBarBackButtonText":@""] isEqualToString:@""]){ backText = [BT_strings getJsonPropertyValue:theScreenData.jsonVars:@"navBarBackButtonText":@""]; } UIBarButtonItem *theBackButtonItem = [[UIBarButtonItem alloc] initWithTitle:backText style:UIBarButtonItemStylePlain target:theViewController action:@selector(navLeftTap)]; [theViewController.navigationItem setLeftBarButtonItem:theBackButtonItem]; [theBackButtonItem release]; }else{ [theViewController.navigationItem setLeftBarButtonItem:nil];
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/16/12 02:47 AM (11 years ago)
Hi in Minny, Totally doable. In fact, in that very same file you can see how an image is used in a UIBarButtonItem for another navigation bar, like the bottom bar used in maps or browser based content. Here's how the map toolbar works with custom images for buttons... UIBarButtonItem* button_1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"map_terrain.png"] style:UIBarButtonItemStylePlain target:theViewController action:@selector(showMapType:)]; button_1.style = UIBarButtonItemStyleBordered; [button_1 setTag:2]; [buttons addObject:button_1]; [button_1 release]; So, in your case, you'll want to do the same type of thing for the "left" or "back" button. Be sure the image is in your project, make the bar button item like this one, and off you go :-) Oh, also, make sure you change the "selector" to trigger the proper method. In this sample fo the map, tapping the button triggers "showMapType" but you'll want to trigger "navLeftTap"
 
Crown Solutions
Aspiring developer
Profile
Posts: 463
Reg: Nov 11, 2011
MN
13,480
like
08/16/12 04:46 AM (11 years ago)
Thanks David!! I got it working, all I had to do it change - initWithTitle:backText --to-- initWithImage:[UIImage imageNamed:@"image_name_here.png"] now it loads. It scaled vertically, but my test image was rather big so it squished it and took up most of the nav bar. I will either choose a smaller image, or try some code-foo to get it to scale automagicly. The more I learn here, the more I am impressed with what you have built here. Thanks!!
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
08/16/12 07:27 AM (11 years ago)
Wow. More great tips. My code is starting to look like swiss cheese with all these hacks/mods. This is great stuff here. --The more I learn here, the more I am impressed with what you have built here. Thanks!! Agreed. I still can't fathom how much I've learned in 6 months playing with this stuff. If only I could find time to play with it more.
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
08/17/12 12:53 AM (11 years ago)
@ATRAIN53: Don't get too excited, the gang needs you in that high rise! We should catch up again. You've set me a few emails and I've followed along with some of your development progress but for sure we should catch up. Expect a call sometime tomorrow (Friday). Hollar back if I get your email and leave a message ;-)
 

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.