gpt4 book ai didi

ios - 如何完全以编程方式添加 UINavigationBar?

转载 作者:行者123 更新时间:2023-12-01 16:33:00 24 4
gpt4 key购买 nike

我想弄清楚,给定 UIViewController子类,如何添加 UINavigationBar给它。所有问题和答案似乎都嵌入到导航 Controller 中(在这种情况下不可能)或通过 Storyboard ,但我需要完全在代码中完成。

我只是将它添加为 View Controller View 的 subview 吗?会不会变成topLayoutGuide在我将它固定到 topLayoutGuide 之后,添加之前的状态栏是哪个?或者我应该在 View Controller 上设置一个我无法弄清楚的属性,而不是添加它?

最佳答案

您在正确的轨道上,您只需像添加任何其他 View 一样添加为 subview 。状态栏的技巧是将自己设置为 navigationBar 委托(delegate)并在委托(delegate)方法中返回 UIBarPositioningTopAttached

.....

self.customNavigationBar.delegate = self;
[self.addSubview self.navigationBar];

....

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
return UIBarPositioningTopAttached;
}

关于ios - 如何完全以编程方式添加 UINavigationBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30813131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com