我有一个导航控制器,我不想用完整个屏幕.特别是,我想在屏幕顶部的栏中放置一个徽标图像.不幸的是,导航控制器似乎不是这样设计的.在界面生成器中,我不能让它占据屏幕的一部分.您将如何实现顶部的徽标图像和占据屏幕其余部分的导航控制器的效果?
我自己没有这样做,但应该很简单.您需要一个包装视图控制器作为其父级(我们称之为 MyWrapperViewController
),其视图层次结构最终可能如下所示:
徽标视图可以是 UIView
、UIImageView
或任何适合内容的类.
当您在某处为您的 MyWrapperViewController
类创建 UINavigationController
时,您可以调整其 view
bounds
的大小小于全屏(可能是屏幕大小减去您的徽标大小,并带有适当的 origin
偏移量,因此它位于徽标下方),然后将其添加为子视图.
I have a navigation controller which I don't want to use up the whole screen. In particular, I want to put a logo image in a bar at the top of the screen. Unfortunately, the navigation controller doesn't seem to be designed this way. In interface builder, I can't make it take up part of a screen. How would you achieve the effect of a logo image up the top and a navigation controller taking up the rest of the screen?
I haven't done this myself, but it should be pretty straight-forward. You'll need a wrapper view controller to be its parent (let's call it MyWrapperViewController
), and its view hierarchy might ultimately look something like this:
UIView -+ (hooked up to the view outlet in MyWrapperViewController) | +-- UIView (Your logo goes here) | +-- UIView (The "child" navigation controller's view)
The logo view can be a UIView
, or a UIImageView
, or whatever class is appropriate for the content.
When you create a UINavigationController
somewhere for your MyWrapperViewController
class, you can resize its view
bounds
to something smaller than full-screen (perhaps the size of the screen minus the size of your logo, with an appropriate origin
offset so it's below the logo), and then add it as a subview.
这篇关于不使用整个屏幕的导航控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!