简体   繁体   English

将后退按钮标题更改为默认的<图标

[英]Changing back button title to default < icon

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. 您可以使用某些字体图标库( 例如ionicons)来获取所需的内容。 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 您可以将此行放入viewDidLoad方法

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)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM