gpt4 book ai didi

ios - 以 UITextField 作为 subview 的 UINavigation

转载 作者:行者123 更新时间:2023-11-28 19:33:50 24 4
gpt4 key购买 nike

我想制作如下的 UI,

enter image description here

我试着像这样增加 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
}
}

这是结果

enter image description here

关于ios - 以 UITextField 作为 subview 的 UINavigation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41277211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com