在导航栏中添加 UIView [英] Add UIView in navigation bar
本文介绍了在导航栏中添加 UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建带有圆角的 UINavigationBar
.它看起来像这样
I want to create UINavigationBar
with rounded corner. It will look like this
我在想的是我添加带有圆角的 UIView
并将其插入导航栏中.所以这是我的代码
What I am thinking is I add UIView
with rounded corner and insert it in navigation bar. So this is my code
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)
从用户界面来看,这很好用.但是后来我的 UIBarButtonItem
丢失了,它被我的自定义视图覆盖并且无法点击.所以我的问题是,如何在导航栏中添加子视图?
By the UI, this works well. But then my UIBarButtonItem
is missing, it covered up by my custom view and couldn't be clicked. So my question is, how to add subview in navigation bar?
谢谢!
推荐答案
只是不要使用 UINavigation 栏并从头开始创建.是最简单的方法.否则,您可以尝试使用图案图像:
Just not use UINavigation bar and create all by scratch. Is the easiest way. Otherwise you can try with pattern image:
navigationController?.navigationBar.backgroundColor = UIColor(patternImage: UIImage(named: "background.png"))
这篇关于在导航栏中添加 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文