在情节提要中添加navigationItem.titleView失败 [英] Adding navigationItem.titleView in storyboard is failing
本文介绍了在情节提要中添加navigationItem.titleView失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以很容易地在代码中将titleView添加到我的navigationItem中:
I can add a titleView to my navigationItem very easily in code:
UIImageView *navImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nav_logo"]];
UIView *titleView = [[UIView alloc] initWithFrame:navImageView.frame];
[titleView addSubview:navImageView];
self.navigationItem.titleView = titleView;
但是,我试图在故事板中执行此操作,但失败了.
However, I'm trying to do this within my storyboard, and am failing miserably.
这就是我所做的:
- 将UIView拖放到我的VC的导航项顶部.
- 将UIImageView拖放到UIView顶部
- 添加宽度/高度/前导/顶部约束
- 设置UIImageView的图片属性
我也将UIView的背景设置为红色(好吧,更像是烧焦的橙色)来说明问题.
I also set the background of my UIView to red (well ok, more like a burnt orange) to illustrate the problem.
这是事物呈现的方式:
我很惊讶这是如此困难.有什么想法吗?
I'm surprised this has been so difficult. Any ideas?
推荐答案
在情节提要界面构建器中
In the storyboard interface builder
- 选择您的视图控制器
- 在属性检查器(⌘⌥4)中的"Simulated Metrics"下,"Top Bar"选择器,选择导航栏之一
- 然后,您应该可以将UIView拖到情节提要上的标题上
- 您可以更改顶部栏"设置回推断"如果您愿意
这是在标题上拖动UIView之后的故事板的图像:
Here is an image of the storyboard after dragging a UIView over the title:
这篇关于在情节提要中添加navigationItem.titleView失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文