iOS Code Snippet Change BackButton Title

Discussion in 'iOS Code Snippets' started by Emme Developer, Jul 27, 2017.

  1. Emme Developer

    Emme Developer Well-Known Member Licensed User

    I search it on forum, but i didn't find nothing.
    This code will change back button Title, instead using name of previus page

    Code:
    Dim na As NativeObject = Me
    na.RunMethod(
    "ChangeTitle::",Array(nav,"Back"))

    #If OBJC
    - (void)ChangeTitle: (UINavigationController*) nav : (NSString*) Title{
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
    barButton.title = Title;
    nav.navigationBar.topItem.backBarButtonItem = barButton;
    }
    #End If
    Nav is the navigation controller; You can change "Back" with what you want
     
    Last edited: Jul 27, 2017
  2. Erel

    Erel Administrator Staff Member Licensed User

    The back button text is the previous page title.

    If you want to set a BarButton then you can also do it with this code:
    Code:
    Dim bb As BarButton
    bb.InitializeText(
    "MyBack""MyBack")

    Dim no As NativeObject = NavControl
    no.GetField(
    "navigationBar").GetField("topItem").SetField("backBarButtonItem", bb)
    This is better as it makes it simpler to customize the button.
     
    Emme Developer likes this.
Loading...