我想更改 UINavigationBar 的高度并添加标题..为什么这么难?
I want to change the height of UINavigationBar and add a title..Why is this so difficult?
我想更改我的 UINavigationBar 的高度并使用 XCode6 添加标题...此导航栏是一个单独的 object 我放置在故事板上的视图控制器内。为什么我不能更改标题或从编辑器中拉伸它?如果我能做到这一点,那就太棒了……但我不能!有人可以为我指明正确的方向,了解如何在 Swift 中以编程方式执行此操作吗?将这段代码放在 viewDidLoad 中是最佳实践吗?另外...对我来说 甚至 视图控制器上的 UINavigationBar 是最佳实践吗?使用 UINavationContoller 与将我正在做的自己的版本拼凑在一起有什么好处。把按钮放在导航栏上真的很容易....为什么我要放一个栏按钮项目?似乎最简单的事情是在 photoshop 中创建一个漂亮的标题栏作为图像,然后在编辑器中将按钮放在它的顶部,而不是与 Interface Builder objects 搏斗......我错了吗?
抱歉,这不是一个好问题...也许问题应该是...我是否应该在 photoshop 中制作一个导航栏并在其上放置按钮而不是处理导航 objects?我现在只使用带有按钮的简单 push segues 进行导航。
如果您想要非常定制的外观,则必须自己制作。根据您的需要(自定义高度)——查看此内容 Is there a way to change the height of a UINavigationBar in Storyboard without using a UINavigationController?
内置的优点是:
- 无需代码即可获得 iOS 外观和感觉
- 后退按钮已填充
- 您可以在所有显示的视图控制器中轻松访问它
In a navigation interface, a navigation controller owns its
UINavigationBar object and is responsible for managing it. It is not
permissible to change the navigation bar object or modify its bounds,
frame, or alpha values directly. However, there are a few properties
that you can modify
更多信息:apple documentation on customizing the nav bar
您可以使用 UIViewController
中的 UINavigationItem
navigationItem 属性 来自定义您的 UINavigationBar
。
// In ViewController
self.navigationItem.titleView = myTitleLabel;
self.navigationItem.rightBarButtonItem = myIcon;
self.navigationItem.leftBarButtonItem = myBackIcon;
我想更改我的 UINavigationBar 的高度并使用 XCode6 添加标题...此导航栏是一个单独的 object 我放置在故事板上的视图控制器内。为什么我不能更改标题或从编辑器中拉伸它?如果我能做到这一点,那就太棒了……但我不能!有人可以为我指明正确的方向,了解如何在 Swift 中以编程方式执行此操作吗?将这段代码放在 viewDidLoad 中是最佳实践吗?另外...对我来说 甚至 视图控制器上的 UINavigationBar 是最佳实践吗?使用 UINavationContoller 与将我正在做的自己的版本拼凑在一起有什么好处。把按钮放在导航栏上真的很容易....为什么我要放一个栏按钮项目?似乎最简单的事情是在 photoshop 中创建一个漂亮的标题栏作为图像,然后在编辑器中将按钮放在它的顶部,而不是与 Interface Builder objects 搏斗......我错了吗?
抱歉,这不是一个好问题...也许问题应该是...我是否应该在 photoshop 中制作一个导航栏并在其上放置按钮而不是处理导航 objects?我现在只使用带有按钮的简单 push segues 进行导航。
如果您想要非常定制的外观,则必须自己制作。根据您的需要(自定义高度)——查看此内容 Is there a way to change the height of a UINavigationBar in Storyboard without using a UINavigationController?
内置的优点是:
- 无需代码即可获得 iOS 外观和感觉
- 后退按钮已填充
- 您可以在所有显示的视图控制器中轻松访问它
In a navigation interface, a navigation controller owns its UINavigationBar object and is responsible for managing it. It is not permissible to change the navigation bar object or modify its bounds, frame, or alpha values directly. However, there are a few properties that you can modify
更多信息:apple documentation on customizing the nav bar
您可以使用 UIViewController
中的 UINavigationItem
navigationItem 属性 来自定义您的 UINavigationBar
。
// In ViewController
self.navigationItem.titleView = myTitleLabel;
self.navigationItem.rightBarButtonItem = myIcon;
self.navigationItem.leftBarButtonItem = myBackIcon;