gpt4 book ai didi

ios - 在导航栏中添加 UIView

转载 作者:行者123 更新时间:2023-11-28 15:18:40 24 4
gpt4 key购买 nike

我想创建带圆角的 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/

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