简体   繁体   English

如何以编程方式设置UIView的topBar和bottomBar参数?

[英]How to set programmatically topBar and bottomBar parameters of UIView?

In the interface builder there are few parameters for UIView of UIViewController: topBar, bottomBar, ... 在界面生成器中,UIViewController的UIView参数很少:topBar,bottomBar,...

在此处输入图片说明 interface builder parameters of view 视图的界面构建器参数

What happens when i set Navigation Bar value for Top Bar parameter, and Tab bar for Bottom Bar parameter? 当我为“顶部栏”参数设置“导航栏”值,为“底部栏”参数设置“标签栏”时会发生什么? It is very useful to me. 对我来说非常有用。

So, how can i do it programmatically? 那么,我该如何以编程方式做到这一点?

Actually this parameters are using for building correct interface and even if you will set this bars in Xcode Interface Builder, they will not appear, if you are not using you UIViewController inside some UIViewController containers. 实际上,此参数用于构建正确的界面,即使您未在某些UIViewController容器中使用UIViewController,即使您在Xcode Interface Builder中设置此条,它们也不会出现。

As example if you will add your UIVIewController into UINavigationController, then you will see Navigation Bar as top Bar. 作为示例,如果您将UIVIewController添加到UINavigationController中,那么您将看到导航栏为顶部栏。 This Simulated metrics have no effect in the program, but they will help you to build correct interface, if you expect to use UIViewController inside container. 此Simulated指标对程序没有影响,但是如果您希望在容器内使用UIViewController,它们将帮助您构建正确的接口。

But if you want to add this Parts of interface programmatically inside your UIViewController, you can use according subiews. 但是,如果要在UIViewController中以编程方式添加接口的此部分,则可以使用相应的子项。 As example: 例如:

UINavigationBar *yourBar = [[UINavigationBar alloc] init];
[self.view addSubview:yourBar];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM