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...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice