gpt4 book ai didi

ios - 在 SwiftUI 的导航栏中设置图像和标题

转载 作者:行者123 更新时间:2023-12-01 15:23:39 30 4
gpt4 key购买 nike

AppStore app has an icon with an image on the right side of the NabBar with Large Title:
如果有人知道如何实现它或如何实现它的想法,我将不胜感激。

最佳答案

这是在 UIKIT 中完成的。
这是代码的样子

let viewA = UIView()
let viewB = UIView()

private func setupNavigationBarAppearance() {

viewA.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didViewA)))
viewB.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(didViewB)))

let leftBarButtonItem = UIBarButtonItem(customView: viewA)
let rightBarButtonItem = UIBarButtonItem(customView: viewB)

navigationItem.leftBarButtonItem = leftBarButtonItem
navigationItem.rightBarButtonItem = rightBarButtonItem
navigationItem.title = "Hello World"

}

@objc private func didViewA() {
print("Hello")
}

@objc private func didViewB() {
print("World")
}
我在这里使用了 UIView,因为 ImageView 是 UIView 的子类,所以你可以将它与你的 ImageView 关联起来。如果不需要,您也可以删除左或右 barButtonItem。

关于ios - 在 SwiftUI 的导航栏中设置图像和标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62756154/

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