Swift
发布时间:2022-03-31 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Swift - 修改导航栏“返回”按钮文字,图标,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
概述
(本文代码已升级至Swift3)
项目中常常会使用 UINavigationController 对各个页面进行导航,导航栏左侧的返回按钮默认标题文字是上级页面的
title 。 但如果上级页面的标题很长,那么这个返回按钮字很多就会很丑: 当文字极其长时返回文字就会变成“
BACk”: 一,要修改“返回按钮”的文字,有如下两种方式: 1,在父页面中设置 将 na
项目中常常会使用
UINavigationController
对各个页面进行导航,导航栏左侧的返回按钮默认标题文字是上级页面的
title
。
但如果上级
页面的
标题很长,那么这个返回按钮字很多就会很丑:
当
文字极其长时返回
文字就会变成“
BACk”:
一,要修改“返回按钮”的文字,有如下两种方式:
1,在父页面中设置
将
navigationItem.BACkBarButtonItem设为
自定义的
UIBarButtonItem
这种
方法所有的子界面返回时都变成了
我们定义的
文字,同时
文字前面任然保留返回箭头。
1
2
|
let
item =
UIBarButtonItem
(title:
"返回"
,style: .plain,target:
self
:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,action:
nil
)
.navigationIte m.BACkBarButtonItem = item
|
@H_197_106@
或者也可以直接把文字设为空字符串,这样就只有一个箭头了。
""
.navigationItem.BACkBarButtonItem = item
@H_197_106@
2,在子页面中设置
将
navigationItem.leftBarButtonItem为自定义的
UIBarButtonItem
这种方式可以给各个子页面返回按钮单独设置不同的文字,但文字前面是没有小箭头的。
2
@H_197_106@
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import
UIKit
|
class
DetailViewController
:
UIViewController
{
override
func
viewDidLoad() {
super
.viewDidLoad()
leftBarBtn =
:1.5em!important; margin:0px!important; overflow:visible!important; padding:1px 0px!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
.navigationIte
m.leftBarButtonItem = leftBarBtn
}
.navigationController!.popViewController(animated:
true
)
}
didReceiveMemoryWarning()
{
.didReceiveMemoryWarning()
}
}
大佬总结
以上是大佬教程为你收集整理的Swift - 修改导航栏“返回”按钮文字,图标全部内容,希望文章能够帮你解决Swift - 修改导航栏“返回”按钮文字,图标所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。