【问题标题】:Swift : How to change navigation controller's height without adding a toolbarSwift:如何在不添加工具栏的情况下更改导航控制器的高度
【发布时间】:2015-07-16 01:09:52
【问题描述】:

如何在不添加工具栏的情况下更改导航控制器的高度? 这是我要构建的苹果 iBooks 应用程序的示例。 我有一个解决方案但并不完美(在导航控制器下方添加一个工具栏但它非常难看)

【问题讨论】:

  • 你总是可以继承 UIView 来创建这个
  • 如果您能在 swift/storyboard 中提供帮助,我将不胜感激

标签: ios swift uinavigationcontroller uisegmentedcontrol uinavigationitem


【解决方案1】:

我想这就是你想要的, 截图

你不能改变导航栏的高度,但你可以在它下面放一个视图,并使用自动布局和阴影使它看起来像导航栏的一部分。将它设置为你制作的类

  1. 编写一个视图作为扩展栏

    class ExtendNavView:UIView{
        override func willMoveToWindow(newWindow: UIWindow?) {
           let scale = UIScreen.mainScreen().scale
           self.layer.shadowOffset = CGSizeMake(0, 1.0/scale)
    
           self.layer.shadowRadius = 0;
           self.layer.shadowColor = UIColor.blackColor().CGColor
           self.layer.shadowOpacity = 0.25
         }
     }
    
  2. 拖一个UIView放到navBar下面,然后设置autolayout让它一直在nav下面

  3. 更改 viewController 中的 navBar 属性

    class ViewController: UIViewController {
        override func viewDidLoad() {
            self.navigationController?.navigationBar.translucent = false
            self.navigationController?.navigationBar.shadowImage = UIImage(named: "TransparentPixel")
         self.navigationController?.navigationBar.setBackgroundImage(UIImage(named:"Pixel"), forBarMetrics:UIBarMetrics.Default)
    
          }
      }
    

这里使用的两张图片(注意:它们是半透明的

像素

url="http://i.stack.imgur.com/gFwyN.png"

透明像素

url = "http://i.stack.imgur.com/zpQw4.png"

你也可以看看 Apple 示例项目,你也可以在那里找到两张图片 https://developer.apple.com/library/ios/samplecode/NavBar/Introduction/Intro.html

【讨论】:

  • 我发布的是使用自动布局,您需要使用自动布局在extendView下制作视图
  • 它不能容纳两行意思栏项目到导航标题的水平
  • 很好的解决方案,但它不能使导航栏半透明,即使在苹果的示例项目中也是如此。
  • 如果你想使用这个解决方案,你不会有半透明的导航栏。
猜你喜欢
  • 1970-01-01
  • 2017-04-06
  • 1970-01-01
  • 2015-11-15
  • 1970-01-01
  • 1970-01-01
  • 2020-05-24
  • 1970-01-01
  • 2017-09-19
相关资源
最近更新 更多