我创建了NavTitleView.xib(添加在这个xib2标签“标题”和“副标题”中),也为这个xib swift文件创建。
然后我想使用这个xib作为navigationItem.titleView
我用viewWillAppear写了这段代码
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(true)
let titleView = NSBundle.mainBundle().loadNibNamed("NavTitleView", owner: self, options: nil)[0] as! NavTitleView
titleView.TitleLabel.text = "My beautiful title"
titleView.SubtitleLabel.text = "My beautiful subtitle"
self.navigationItem.titleView = titleView
}所有的工作都很棒!但是当我的视图出现时-这个NavTitleView会从左边跳到中间!我不明白为什么?如何修复它?
发布于 2016-07-13 05:36:37
如果设置了rightBarButtonItem,请尝试在viewWillAppear中再次调用self.navigationItem.rightBarButtonItem = UIBarButton
https://stackoverflow.com/questions/36510829
复制相似问题