当我按下a时UIViewController
,它在new的后退按钮中有一些标题UIViewController
,如果标题中包含很多文本,则在iPhone
4s中看起来不太好,所以我想删除它。
如果我在prepareForSegue
函数中添加一些代码,那将是一个麻烦。
还有更好的方法吗?
如果要返回箭头,则将以下代码放入AppDelegate
文件中didFinishLaunchingWithOptions
。
For Objective-C
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
For Swift
let BarButtonItemAppearance = UIBarButtonItem.appearance()
BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)
另一个选择在下面给出。
在 Objective C
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
在 Swift
self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil)
更新:
let BarButtonItemAppearance = UIBarButtonItem.appearance()
let attributes: [NSAttributedStringKey: Any] = [
BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 0.1),
NSAttributedStringKey.foregroundColor: UIColor.clear]
BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .normal)
BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .highlighted)
更新SWIFT 4.1:
let attributes = [NSAttributedStringKey.font: UIFont(name: "Helvetica-Bold", size: 0.1)!, NSAttributedStringKey.foregroundColor: UIColor.clear]
BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .normal)
BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .highlighted)
使用偏移
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(-1000, 0), for:UIBarMetrics.default)
因此可能是您的问题已解决。
快乐的编码。
问题内容: 如何更改导航栏的后退按钮的字体。 后退按钮可以是“后退”,也可以是前一个视图控制器的标题。 我认为这可以工作: 但可选的return 。 问题答案: 刚刚测试了您的代码,看来行返回的原因实际上是因为返回nil。因此,如果您将该属性设置为有效的字体名称,则代码应该运行无错误- 即使显式设置为nil。 但是无论如何,正如我在测试中看到的那样,这条线不会给您显然想要的结果。前导的可选内容不应
我在我的应用程序中使用底部导航,如下所示。 我想从底部导航的每个页面都有一个不同的(一些应用程序栏有不同的图标和标题。因此不能在AppMainPage中使用普通的应用程序栏)脚手架小部件内的AppBar如下所示。 主页appbar代码 我不确定我的代码实现是否符合我的要求,如果有人能在这方面提供帮助,我很高兴。
问题内容: 我正在尝试在控制器的导航栏中设置后退按钮图像,这是viewDidLoad()中的代码: 我试图将它们放到viewWillLoad中,但是得到了同样的错误 控制台出现错误消息: 我不知道哪一部分出了问题。似乎back_img不是nil,但我收到错误消息说它为nil 谢谢! 问题答案: 我已经研究了示例代码。1)在情节提要中创建一个条形按钮项。2)使用IBOutlet将按钮链接到控制器3)
我开始创建一个应用程序,它使用一个活动(导航抽屉)和许多片段。但我无法使用工具栏上的“后退”按钮从片段中导航回来。硬件后退按钮工作正常。我知道我需要覆盖选项ItemSelected,捕捉android。R、 id.home,检查后堆栈中是否有内容,然后弹出它。在更改片段后,“burger”按钮变为“back arrow”,但当我单击它时,选项ItemSelected将打开NavigationDra
我想在标题栏区域放一个后退按钮,在Android应用程序中继续后退活动,如何放那个按钮。 就像这张照片里的一样。
问题内容: 现在我有两个视图控制器。我的问题是,更改为第二个视图控制器后,我不知道如何隐藏后退按钮。主要是我在Objective-C中找到的参考。如何快速编码? 在Objective-C中隐藏后退按钮代码 问题答案: 根据该文件为: