ios - swift : How to change navigation controller's height without adding a toolbar

标签 ios swift uinavigationcontroller uisegmentedcontrol uinavigationitem

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

ibook Nav Controller is perfect

I added a toolbar below the nav controller

最佳答案

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

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

  1. 写一个view作为extendbar

    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下面 enter image description here

  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 example project,你也可以在那里找到两张图片 https://developer.apple.com/library/ios/samplecode/NavBar/Introduction/Intro.html

关于ios - swift : How to change navigation controller's height without adding a toolbar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31443801/

相关文章:

ios - 从 splitviewcontroller 中的 masterVewController 访问 ROOTDetailViewController

ios - 如何保存导航 Controller 的状态? (iOS 6 之前)

swift - 节点启动后如何更新SKLabelNode颜色?

ios - 代码行数和文件数;哪一个增加了应用程序的大小?

iOS - 导航 Controller 后退按钮

ios - 从 firebase 数据库更新数组值

json - 从 Swift 发送到 Node.js 的无效 JSON

ios - 如何在ios swift中使用xib将UINavigationController设置为rootviewcontroller?

iOS 过滤 tableview 导航推送 UIView,然后 UIView 返回导致崩溃

ios - 移动网站无法在iframe中呈现移动设备