Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back-like arrow on iOS 7

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?

This is how it's supposed to look like

like image 224
johnyu Avatar asked Dec 19 '13 17:12

johnyu


3 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: enter image description here

like image 196
staticVoidMan Avatar answered Oct 03 '22 09:10

staticVoidMan


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];
like image 21
Kaveh Vejdani Avatar answered Oct 03 '22 07:10

Kaveh Vejdani


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; 
 }
like image 41
onegray Avatar answered Oct 03 '22 08:10

onegray