如何在不添加工具栏的情况下更改导航 Controller 的高度? 这是我要构建的苹果 iBooks 应用程序的示例。 我有一个解决方案,但并不完美(在导航 Controller 下方添加了一个工具栏,但它非常难看)
最佳答案
我想这就是你想要的, 截图
你不能改变导航栏的高度,但你可以在它下面放一个 View ,并使用自动布局和阴影使它看起来像导航栏的一部分。将它设置为你制作的类
写一个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 } }
拖一个UIView放到navBar下面,然后设置autolayout让它一直在nav下面
更改 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/