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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.