I made a custom back button but I want to change the title to the default arrow "<" how do I do this? This is what I currently have
let newBackButton = UIBarButtonItem(title: "<", style: UIBarButtonItemStyle.Plain, target: self, action: "back:")
I need "Back" to be the default "<" icon. When I type it in as text it's just a small ugly text button.
You can use some font-icon library like ionicons to get what you need. In provided link there are library and examples how install and how to use it. It's quite useful because with a font icon you don't need to bother with image sizes and scaling.
To set "back" icon on button you only need to do something like this:
self.button.setTitle(String.fontIonIconWithName("ios-arrow-back"), forState: .Normal)
Here is official website where you can find all available icons.
You could put this line into viewDidLoad
method
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
This way you will get standard "<" sign without any label
EDIT
Swift notation:
override func viewDidLoad() {
super.viewDidLoad()
// only standard '<' will appear; proper target and action will be added automatically
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain , target: nil, action: nil)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.