Back-like arrow on iOS 7

前端 未结 4 1333
深忆病人
深忆病人 2021-02-20 07:14

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

相关标签:
4条回答
  • 2021-02-20 07:54

    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; 
     }
    
    0 讨论(0)
  • 2021-02-20 07:55

    Look at the UIBarButtonSystemItem enum under contants in the UIBarButtonItem documentation:

    https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40007519-CH3-SW2

    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.

    0 讨论(0)
  • 2021-02-20 08: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];
    
    0 讨论(0)
  • 2021-02-20 08:12

    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

    0 讨论(0)
提交回复
热议问题