I'd love to create a "back" left-arrow-bezel button in a UIToolbar
.
As far as I can tell, the only way to get one of these is to leave UINavigationController
at default settings and it uses one for the left bar item. But there's no way I can find to create one as a UIBarButtonItem
, so I can't make one in a standard UIToolbar
, even though they're very similar to UINavigationBar
s.
I could manually create it with button images, but I can't find the source images anywhere. They have alpha-channel edges, so screenshotting and cutting won't get very versatile results.
Any ideas beyond screenshotting for every size and color scheme I intend to use?
Update: PLEASE STOP dodging the question and suggesting that I shouldn't be asking this and should be using UINavigationBar
. My app is Instapaper Pro. It shows only a bottom toolbar (to save space and maximize readable content area), and I wish to put a left-arrow-shaped Back button in the bottom.
Telling me that I shouldn't need to do this is not an answer and certainly doesn't deserve a bounty.
I used the following psd that I derived from http://www.teehanlax.com/blog/?p=447
http://www.chrisandtennille.com/pictures/backbutton.psd
I then just created a custom UIView that I use in the customView property of the toolbar item.
Works well for me.
Edit: As pointed out by PrairieHippo, maralbjo found that using the following, simple code did the trick (requires custom image in bundle) should be combined with this answer. So here is additional code:
First of all you have to find an image of the back button. I used a nice app called Extractor that extracts all the graphics from iPhone. In iOS7 I managed to retrieve the image called
UINavigationBarBackIndicatorDefault
and it was in black colour, since I needed a red tintI change the colour to red using Gimp.EDIT:
As was mentioned by btate in his comment, there is no need to change the color with the image editor. The following code should do the trick:
Then I created a view that contains an imageView with that arrow, a label with the custom text and on top of the view I have a button with an action. Then I added a simple animation (fading and translation).
The following code simulates the behaviour of the back button including animation.
EDIT:
Instead of adding the button, in my opinion the better approach is to use a gesture recognizer.
Solution WITHOUT using a png. Based on this SO answer: Adding the little arrow to the right side of a cell in an iPhone TableView Cell
Just flipping the UITableViewCell horizontally!
WARNING: There are reports that this will not work on iOS 6. This might only work on older versions of the OS. Evidently at least one dev has had their app rejected for using this trick (see the comments). Use at your own risk. Using an image (see answer above) might be a safer solution.
This can be done without adding in your own image files using sekr1t button type 101 to get the correct shape. For me the trick was figuring out that I could use
initWithCustomView
to create theBarButtonItem
. I personally needed this for a dynamic navbar rather than atoolbar
, but I tested it with a toolbar and the code is nearly the same:If you're doing this on a toolbar you'll have to tweak how you set the items, but that depends on the rest of your code and I leave that as an exercise for the reader. :P This sample worked for me (compiled & run).
Blah blah, read the HIG, don't use undocumented features, and all that. There's only six supported button types and this isn't one of them.
You can find the source images by extracting them from Other.artwork in UIKit ${SDKROOT}/System/Library/Frameworks/UIKit.framework/Other.artwork. The modding community has some tools for extracting them, here. Once you extract the image you can write some code to recolor it as necessary and set it as the button image. Whether or not you can actually ship such a thing (since you are embedding derived artwork) might be a little dicey, so maybe you want to talk to a lawyer.
I found that using the following, simple code did the trick (requires custom image in bundle):