Gap between navigation bar and subview ios?

依然范特西╮ 提交于 2019-12-12 09:59:36

问题


I understand there is this question: Adding subview leaves gap between subview and navigation bar

However, there is no answer, and I do my method a different way, so that might make it a bit different. Anyways, I as well have a gap between the navigation bar and subview when I add a subview to my navigation controller, which also has a tab bar controller. I am using storyboards. I am adding the subview using UIViewController.view type via storyboard id.

My code:

[self.view addSubview:[[self.storyboard instantiateViewControllerWithIdentifier:@"View"] view]];

This works, and adds the view, but with the gap above it. Any suggestions? Thanks.


回答1:


On your 'View' view controller defined in Storyboard, set the 'Resize View From NIB' property to unticked (this is ticked by default). This cured the gap problem for me.




回答2:


I solved it by setting the translucent property of UINavigationController to NO. Add the following line in viewDidLoad

self.navigationController.navigationBar.translucent = NO;


来源:https://stackoverflow.com/questions/15801365/gap-between-navigation-bar-and-subview-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!