gpt4 book ai didi

ios - 为什么我不能在 UINavigationController 中更改后退按钮的字体?

转载 作者:行者123 更新时间:2023-11-28 12:38:25 25 4
gpt4 key购买 nike

我想更改导航 Controller 的文本和字体。

我有一个静态的 UITableView,当用户单击一个单元格时 - 我通过 segue 转到第二个 UIViewController。

我在 Storyboard和我的代码中设置了 segue 的名称:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "myTestSegue") {
if segue.destination is MyTest {
print("can I see it?")
let backButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.plain, target: self, action: nil)
backButton.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "AppleSDGothicNeo-Light", size: 20.0)!], for: UIControlState())
navigationItem.backBarButtonItem = backButton
}
}
}

现在,当我运行应用程序并单击单元格时,我在控制台中看到:我可以看到它吗?,但是下一个面板上按钮的文本和字体没有改变。

我错过了什么?

最佳答案

您可以使用此代码更改后退按钮的字体样式。

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor whiteColor],
NSShadowAttributeName:shadow,
NSFontAttributeName:[UIFont boldSystemFontOfSize:15.0]
}
forState:UIControlStateNormal];

关于ios - 为什么我不能在 UINavigationController 中更改后退按钮的字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40193039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com