gpt4 book ai didi

swift - 将 NavigationBar subview 放在 NavigationBarItem 和标题后面

转载 作者:行者123 更新时间:2023-11-30 10:31:38 24 4
gpt4 key购买 nike

我想在导航栏上的所有内容下方添加一个 View 。我需要将它们作为 subview 添加到我的导航栏,以便它们出现在任何详细 View Controller 上。

这是我迄今为止在自定义 NavigationBar 子类中尝试的内容(我在 layoutSubviews() 中调用此方法):

private var backgroundView = UIView()

backgroundView.frame = CGRect(x: 0, y: 0, width: 100, height: 70)
backgroundView.backgroundColor = .blue
backgroundView.alpha = 0.7
self.insertSubview(backgroundView, at: 0)

这就是我得到的:

navigationBar with subview

backgroundView 出现在标题和 NavigationBarItem 的顶部

我能做什么?

最佳答案

根据this post在苹果开发者论坛上,您可以在 NavigationBar 类中执行此操作(有效!):

self.subviews[0].insertSubview(backgroundView, at: 0)

关于swift - 将 NavigationBar subview 放在 NavigationBarItem 和标题后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59085151/

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