简体   繁体   English

自定义iOS导航栏高度,添加背景,菜单按钮(Swift)

[英]Customizing iOS Navigation Bar height, add background, menu button (Swift)

I've started developing in iOS last week and I've been trying to accomplish the following design to the Nav bar of my iOS app. 我上周开始在iOS上开发,我一直在尝试将以下设计完成到我的iOS应用程序的导航栏中。 So far, all I can do is change the background and add an image in the center. 到目前为止,我所能做的就是改变背景并在中心添加图像。 How do I resize the height of the navigation bar, add background and the buttons? 如何调整导航栏的高度,添加背景和按钮?

在此输入图像描述

You can easily do this in a storyboard, or adding constraints via code. 您可以在故事板中轻松完成此操作,或通过代码添加约束。

Place a toolbar on top with these constraints: 使用这些约束将工具栏放在顶部:

  1. Top Space to Superview = 0 Superview的顶级空间= 0
  2. Leading Space to Superview = 0 Superview的领先空间= 0
  3. Trailing Space to Superview = 0 跟踪空间到Superview = 0
  4. Height Equals = 80 (or whatever value you want) 高度等于= 80(或任何你想要的值)

Place navigation bar below the toolbar with these constraints: 使用以下约束将导航栏放在工具栏下方:

  1. List item 项目清单
  2. Top Space to the Toolbar = 0 工具栏的顶部空间= 0
  3. Leading Space to Superview = 0 Superview的领先空间= 0
  4. Trailing Space to Superview = 0 跟踪空间到Superview = 0
  5. Height Equals = 64 (or whatever value you want) 高度等于= 64(或您想要的任何值)

Add items to you Toolbar starting from the left: 从左侧开始向您添加项目工具栏:

  1. Add a Bar Button Item for the Menu Button 为菜单按钮添加条形按钮项
  2. Add a Flexible Space Bar Button Item 添加灵活空格键按钮项
  3. Add a Bar Button Item for the Owl Button Image 为猫头鹰按钮图像添加条形按钮项
  4. Add a Flexible Space Bar Button Item 添加灵活空格键按钮项

Add items to your Navigation Bar: 将项目添加到导航栏:

  1. Add a Bar Button Item for the Back Button 为后退按钮添加条形按钮项

Storyboard Example 故事板示例

示例图像

I don't believe Apple allows you to change the height of the navigation bar. 我不相信Apple允许您更改导航栏的高度。 However, certain visual attributes can be altered, such as background image. 但是,某些视觉属性可以更改,例如背景图像。

Refer to this document: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationBar_Class/index.html#//apple_ref/doc/uid/TP40006887-CH3-SW16 请参阅此文档: https//developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationBar_Class/index.html#//apple_ref/doc/uid/TP40006887-CH3-SW16

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM