正如标题所示,我在导航栏中使用UIButton作为titleView。有没有办法让UIButton和导航栏一起变大?当我设置self.navigationController?.navigationBar.prefersLargeTitles = true时,我得到的结果是这样的,

发布于 2017-10-22 04:21:48
我找不到任何关于这方面的文档,所以我试了一下。似乎在iOS 11中,你不能让标题变成一个按钮,并在左边大屏显示。
另外,我调整了按钮的边框大小(添加在下面)。我无法增加按钮的大小,无论我将框架设置为什么。
为了重新创建,我设置了一个单一视图项目。我将视图控制器嵌入到导航控制器中。
在ViewController.swift的viewDidLoad中,我添加了以下代码:
let titleButton = UIButton(type: .roundedRect)
titleButton.setTitle("Hello Button!", for: UIControlState.normal)
let navController = parent as! UINavigationController
navController.navigationBar.topItem!.title = "Hello???"
navController.navigationBar.topItem!.titleView = titleButton
navController.navigationBar.prefersLargeTitles = true这看起来与您的示例类似。
如果我为,则为
.title设置为空字符串,或将行重新标记出来:导航栏已拉伸,且未显示标题文本(或在界面生成器中设置的标题文本显示).prefersLargeTitles,或将其设置为false:导航栏为正常高度,按钮显示,但没有标题文本显示在titleView行之外,并且:<.prefersLargeTitles>F216false>
- leave the `.prefersLargeTitles` set to `true`: the `title` text displays large at the left, and the navbar's height is stretched.
- set the `.prefersLargeTitles` to `false`: the `title` text displays in the top center, and the navbar is normal height.
https://stackoverflow.com/questions/46865301
复制相似问题