ios - 如何更改导航 Controller 后退按钮的字体大小

标签 ios swift uinavigationcontroller swift4

我试图更改导航 Controller 后退按钮的字体大小,但无济于事。

我目前在以前的 View Controller 中执行此操作 viewWillAppear:

 navigationController?.navigationBar.backItem?.backBarButtonItem?.setTitleTextAttributes(
    [NSAttributedStringKey.font : UIFont.systemFont(ofSize: 5)], for: .normal)

上面的代码什么也没做.. 那么,两个问题。

首先,更改后退按钮字体大小的正确方法是什么(顺便说一下,这似乎比应该的要困难得多)。

其次,是否有一个单一的地方(如 AppDelegate)我可以进行此更改以影响所有 View Controller ?

最佳答案

您可以在 AppDelegate 中更改它:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font: UIFont(name: "SF Pro Display", size: 17)!], for: .normal)

    return true
}

您可以在其中自定义导航栏按钮的字体和大小,以便它在所有 View Controller 中发生变化。

关于ios - 如何更改导航 Controller 后退按钮的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48733365/

相关文章:

swift - 如何将 View Controller 推送到生成的导航层次结构中

ios - 如何在导航栏中设置父 View 的文本字段全宽

ios - 基于按钮按下 Swift 在 sameTableViewController 中加载数据

iphone - 在方法中返回自定义的 UIButton?

ios - 立即将 tableView 滚动到 indexPath

macos - 如何禁用 NSTextView 中图像的标记选项?

ios - 在我的 swift 应用程序中将 NSData 解析为 Json 失败

ios - 如何对 Cloudkit 记录执行文本搜索?

iphone - AVCaptureVideoPreviewLayer镜像iPhone 4和iPad 2

ios - 阻止导航 Controller 影响其他 View Controller