设置导航栏标题背景颜色(swift) [英] Set navbar title background color (swift)
本文介绍了设置导航栏标题背景颜色(swift)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改 iOS 中 UI 导航栏标题的背景.我希望最终结果如下图所示:
请告诉我这是否可行,或者我是否必须采取解决方法.
I am wanting to change the background of the UI Navbar title in iOS. I want the final result to appear like the image below:
Please let me know if this is possible or if I will have to do a workaround.
Changing navigation bar color in Swift does not address the background color of the title text for the UINavigationBar
解决方案
So basically you need to add a UIView to the navigationBarTitleView. Then add a label or UIImageView to the Uiview and Finaly add that view to the TitleView. So here I've added label to the titleView. Hope that this will gonna help you:-
override func viewDidLoad() {
super.viewDidLoad()
let navBarView: UIView = UIView()
navBarView.frame = CGRectMake(0, 0, 100.0, 21.0)
let label: UILabel = UILabel()
label.frame = CGRectMake(0, 0, 90.0, 21.0)
label.text = "Your Title"
label.textAlignment = .Center
label.backgroundColor = UIColor.grayColor()
navBarView.addSubview(label)
self.navigationItem.titleView = navBarView
// Do any additional setup after loading the view, typically from a nib.
}
So here is the output :-
这篇关于设置导航栏标题背景颜色(swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文