I need to add a left bar button item in my app that looks like system back button, but is not the system back button, since it will appear on view controller that is the only vc of my navController's stack and execute my own code. Simply writing "Back" isn't really good for me, as I need to display the "<" arrow as well. Is there a way to programmatically create an arrow like that, without making image with that arrow?
-
possible duplicate of [Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar](http://stackoverflow.com/questions/227078/creating-a-left-arrow-button-like-uinavigationbars-back-style-on-a-uitoolba) – Fruity Geek Dec 19 '13 at 18:07
-
2Note that the suggested duplicate is a much older question, dating to 2008, with only [one answer](http://stackoverflow.com/a/18874211/643383) relevant to iOS 7. Further, the OP here has specifically asked for a solution different from that described in that one answer. Let's not be too quick to close this as a duplicate. – Caleb Dec 19 '13 at 18:43
4 Answers
You can use any Unicode character (anywhere in your code) for this.
You can find what you want here:
Xcode > Edit > Special Characters...
Search for arrow
or back
or browse the categories.
Then copy paste the character where required (in the XIB object's title or in the setTitle
or setText
methods like any other character)
something like:

- 19,275
- 6
- 69
- 98
-
2There is no arrow in unicode that looks like the one in back (at least not with that size). – johnyu Dec 30 '13 at 10:36
-
@johnyu : take a screenshot of what you're expecting and add it to your question – staticVoidMan Dec 30 '13 at 11:49
-
-
@johnyu : hmm.. i see a few but the only problem is that setting title to "`〈 Back`" exposes the subtle misalignment between the "`〈`" and "`Back`". anyways... i'll check for something good – staticVoidMan Dec 30 '13 at 14:58
-
I'll probably just have to use the image of that arrow. But thanks for help. – johnyu Dec 30 '13 at 15:00
Try this:
// After you create and place your backButton:
UILabel* arrowLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 20, 20)];
arrowLabel.text = @"<";
arrowLabel.textColor = [backButton titleColorForState:UIControlStateNormal];
arrowLabel.transform = CGAffineTransformMakeScale(1,2);
[backButton addSubview:arrowLabel];
If addSubview gives you trouble, try
[backButton insertSubview:arrowLabel atIndex:0];

- 224
- 1
- 6
-
+1 for the idea. Some improvements for positioning and clarity: (1) CGRectMake(-12, -1, 20, 30), (2) arrowLabel.font = [UIFont systemFontofSize:40], (3) MakeScale(0.65,1.25). – Jeff Dec 18 '18 at 06:53
Consider using a dummy UIViewController
as a root view controller for your UINavigationController
’s stack:
[[UINavigationController alloc] initWithRootViewController:[UIViewController new]];
[navController pushViewController:viewController animated:NO];
Then you can use my BackButtonHandler extension to handle back button action (as described in this thread) :
-(BOOL) navigationShouldPopOnBackButton {
[self dismissModalViewControllerAnimated:YES];
return NO;
}
Look at the UIBarButtonSystemItem
enum under contants in the UIBarButtonItem documentation:
These are all of the button styles provided by Apple:
typedef enum {
UIBarButtonSystemItemDone,
UIBarButtonSystemItemCancel,
UIBarButtonSystemItemEdit,
UIBarButtonSystemItemSave,
UIBarButtonSystemItemAdd,
UIBarButtonSystemItemFlexibleSpace,
UIBarButtonSystemItemFixedSpace,
UIBarButtonSystemItemCompose,
UIBarButtonSystemItemReply,
UIBarButtonSystemItemAction,
UIBarButtonSystemItemOrganize,
UIBarButtonSystemItemBookmarks,
UIBarButtonSystemItemSearch,
UIBarButtonSystemItemRefresh,
UIBarButtonSystemItemStop,
UIBarButtonSystemItemCamera,
UIBarButtonSystemItemTrash,
UIBarButtonSystemItemPlay,
UIBarButtonSystemItemPause,
UIBarButtonSystemItemRewind,
UIBarButtonSystemItemFastForward,
UIBarButtonSystemItemUndo, // iOS 3.0 and later
UIBarButtonSystemItemRedo, // iOS 3.0 and later
UIBarButtonSystemItemPageCurl, // iOS 4.0 and later
} UIBarButtonSystemItem;
Perhaps rewind or undo would be close enough for you.

- 1,625
- 12
- 18