ios - 在导航栏中添加 UIView

标签 ios swift uinavigationcontroller uinavigationbar

我想创建带圆角的 UINavigationBar。它看起来像这样 rounded navigation bar

我在想的是添加带有圆角的 UIView 并将其插入导航栏。所以这是我的代码

let roundView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 44))
roundView.backgroundColor = UIColor.whiteBackground
roundView.roundCorners(corners: [.topLeft, .topRight], radius: 20)
navigationController?.navigationBar.insertSubview(roundView, at: 0)
setTitleTextColor(color: UIColor.black)

通过 UI,这很好用。但是后来我的 UIBarButtonItem 不见了,它被我的自定义 View 覆盖了,无法点击。所以我的问题是,如何在导航栏中添加 subview ?

谢谢!

最佳答案

只是不使用导航栏并从头开始创建。是最简单的方法。否则你可以尝试使用图案图像:

navigationController?.navigationBar.backgroundColor = UIColor(patternImage: UIImage(named: "background.png"))

关于ios - 在导航栏中添加 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46401024/

相关文章:

ios - 如何从惰性集变量内的完成处理程序返回

ios - Quickblox:我在加入/离开聊天室时收到 EXC_BAD_ACCESS(code=1, address"mem-address")

ios - Testflight 在 Appstore 上构建

ios - presentingViewController 不工作

ios - 在 Swift 中使用更新函数的更清洁(更好)替代方法

arrays - 识别数组中的重复项

ios - 弹出动画在 UITabbarController 的第一个 UINavigationController 中不起作用

ios - 在 Swift 中从 AppDelegate 加载嵌入到 UINavigationController 的 Controller

ios - 如何删除和添加导航栏上的 "back button"

ios - 是什么导致基本本地化创建重复的 Storyboard文件?