【发布时间】:2020-01-07 06:31:29
【问题描述】:
我想要自定义导航栏后退按钮标题和动作。
我的形象:
我需要这样的后退按钮。在这里,我成功添加了文本,但没有添加返回箭头。这里我的代码有返回按钮的动作。
这是我的代码
//Custom barButtonItem with custom alert function
self.navigationItem.hidesBackButton = true
let newBackButton = UIBarButtonItem(title: "< Dialer", style: .plain, target: self, action: #selector(back(sender:)))
self.navigationItem.leftBarButtonItem = newBackButton
【问题讨论】:
-
我试过
NSMutableAttributedString,但它不起作用。我的代码是let attrString = NSMutableAttributedString(string: "<", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 18)]) attrString.append(NSMutableAttributedString(string: " Dialer", attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 36)])) -
let newBackButton = UIBarButtonItem(title: "\(attrString)", style: .plain, target: self, action: #selector(back(sender:))) -
这段代码对我很有帮助....stackoverflow.com/questions/27499998/…
标签: ios swift cocoa-touch uinavigationcontroller uibarbuttonitem