Items often use Uinavigationcontroller to navigate the individual pages, the return button on the left-hand side of the navigation bar, the default title text is the parent page title.
But if the title of the superior page is very long, the return button Word will be very ugly:
Returning text when the text is extremely long becomes "back":
One, to modify the "Back button" text, like the next two ways:
1, set in the parent page
Set Navigationitem.backbarbuttonitem as a custom Uibarbuttonitem
In this way, all of the child interfaces return to the text we define, while the text remains in front of the return arrow.
Let item = Uibarbuttonitem (title: "Back", Style:. Plain, Target:self, Action:nil)
Self.navigationItem.backBarButtonItem = Item;
Or you can simply set the text to an empty string so that there is only one arrow.
Let item = Uibarbuttonitem (title: "", Style:. Plain, Target:self, Action:nil)
Self.navigationItem.backBarButtonItem = Item;
2, set in sub page
Navigationitem.leftbarbuttonitem to Custom Uibarbuttonitem
This way you can give each child page return button to set different text, but there is no small arrow in front of the text.
Import Uikit
Class Detailviewcontroller:uiviewcontroller {
Override Func Viewdidload () {
Super.viewdidload ()
Let leftbarbtn = Uibarbuttonitem (title: "Back", Style:. Plain, Target:self,
Action: "Backtoprevious")
Self.navigationItem.leftBarButtonItem = leftbarbtn
}
Return button click Response
Func backtoprevious () {
Self.navigationcontroller? Popviewcontrolleranimated (True)
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}
Second, modify the "Back button" icon
As you can see from the last example above, only text does not have a picture when you modify the return button on a subpage. If you want to use a custom picture, or if the picture text needs to do the following:
1, if only need picture, do not need text
For example, we want to use the picture on the left (Back@2x.png) as the return icon
Import Uikit
Class Detailviewcontroller:uiviewcontroller {
Override Func Viewdidload () {
Super.viewdidload ()
Let leftbarbtn = Uibarbuttonitem (title: "", Style:. Plain, Target:self,
Action: "Backtoprevious")
Leftbarbtn.image = UIImage (named: "Back")
To remove the left space, or the button is not on top of the front
Let spacer = Uibarbuttonitem (barbuttonsystemitem:. Fixedspace, Target:nil, Action:nil)
Spacer.width =-10;
Self.navigationItem.leftBarButtonItems = [Spacer, LEFTBARBTN]
}
Return button click Response
Func backtoprevious () {
Self.navigationcontroller? Popviewcontrolleranimated (True)
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}
2, you need both pictures and text
This is the time to create a uibutton to achieve
Import Uikit
Class Detailviewcontroller:uiviewcontroller {
Override Func Viewdidload () {
Let button = UIButton (type:. System)
Button.frame = CGRectMake (0, 0, 65, 30)
Button.setimage (UIImage (named: "Back"), Forstate:. Normal)
Button.settitle ("Back", Forstate:.) Normal)
Button.addtarget (Self, Action: "Backtoprevious", forControlEvents:. Touchupinside)
Let leftbarbtn = Uibarbuttonitem (Customview:button)
To remove the left space, or the button is not on top of the front
Let spacer = Uibarbuttonitem (barbuttonsystemitem:. Fixedspace, Target:nil, Action:nil)
Spacer.width =-10;
Self.navigationItem.leftBarButtonItems = [SPACER,LEFTBARBTN]
}
Return button click Response
Func backtoprevious () {
Self.navigationcontroller? Popviewcontrolleranimated (True)
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}