Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inverting UIBarButtonItem "Play" for use as a Back Button?

Okay, simple enough.

I'm coding up a simple web view, and I'm providing a few Safari-like controls for navigation.

Play seems to be the obvious choice for the forward button, but I'd like to have a Back Button as well, as seen in several Apple and third party apps.

Is there a way to invert the icon, so that it points backwards, or are all the apps using this setup using images to replicate this functionality?

like image 747
DVG Avatar asked Jul 07 '10 23:07

DVG


2 Answers

Unicode is your friend here.

Create a UIBarButtonItem (in Interface Builder or in code) and set it to "Custom" where you can enter text for the button.

Now use these Unicode characters to simulate the back & forward buttons:

◄ and ►

I use it in my apps and it looks great.

like image 184
Tal Bereznitskey Avatar answered Nov 10 '22 13:11

Tal Bereznitskey


I know this was answered long ago, however just to add...

Yes, you can use Unicode but it does not look the same as the standard ios button. And if you have strict requirements to match ios look than you will need to at least make an image for the back button, in this case by simply downloading the play image and flipping it.

UIImage *image = [UIImage imageNamed:@"backButton.png"];
UIButton *btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
[btnBack setImage:image forState:UIControlStateNormal];
btnBack.frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);

UIBarButtonItem * btnItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
[btnItem addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
// add it to your bar
self.navigationItem.leftBarButtonItem = btnItem;

(wrote it without spell checking... so beware of spelling errors that may have resulted)

// button images are here. http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/IconsImages/IconsImages.html

like image 27
Chris Avatar answered Nov 10 '22 13:11

Chris