我想制作如下的 UI,
我试着像这样增加 UINavigationController 的高度
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, 320, 110)];
但导航标题和 BarButtonItem 出现在下方。 我无法添加隐藏导航,因为我正在使用使用 Left BarButtonItem 的第三方侧边菜单。
我可以很好地保持导航的原样,在下面我添加了 uiview 作为 subview ,其背景颜色与导航的背景颜色相同,但两者之间出现细线...:(
最佳答案
您不能增加 UINavigationBar 的高度。在 UINavigationBar 下方添加一个包含这些元素的 UIView。
UINavigationBar 下方会多出一行。您可以删除该行。引用How to hide iOS7 UINavigationBar 1px bottom line
或者使用这段代码(我刚刚从那个链接中快速复制了它,将它转换为 Objective-C)
import UIKit
class ViewController: UIViewController {
private var shadowImageView: UIImageView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if shadowImageView == nil {
shadowImageView = findShadowImage(under: navigationController!.navigationBar)
}
shadowImageView?.isHidden = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
shadowImageView?.isHidden = false
}
private func findShadowImage(under view: UIView) -> UIImageView? {
if view is UIImageView && view.bounds.size.height <= 1 {
return (view as! UIImageView)
}
for subview in view.subviews {
if let imageView = findShadowImage(under: subview) {
return imageView
}
}
return nil
}
}
这是结果
关于ios - 以 UITextField 作为 subview 的 UINavigation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41277211/