swiftui - 在 Touch Bar 中显示 TabView 元素 - SwiftUI
问题描述
我正在开发一个 Mac 应用程序(通过 Mac Catalyst),我也在寻找一种在 Touch Bar 中显示 TabView 项目的方法......
我尝试使用 .touchBar 修饰符、targetEnvironment(macCatalyst) 以及#if os(macOS),但没有运气......
有什么建议么?
这是我的代码:
import SwiftUI
let furl = URL(fileURLWithPath: "path")
struct ContentView: View {
@State private var selected = 0
@State private var isActive = false
var body: some View {
TabView(selection: $selected) {
NavigationView {
HomeView()
}
.navigationViewStyle(StackNavigationViewStyle())
.tabItem {
Image(systemName: (selected == 0 ? "house.fill" : "house"))
Text("Home")
}.tag(0)
NavigationView {
CategoryView(dm: DownloadManager())
}
.navigationViewStyle(DoubleColumnNavigationViewStyle())
.tabItem {
Image(systemName: (selected == 1 ? "text.justify" : "text.justify"))
Text("Categorie")
}.tag(1)
NavigationView {
GalleryView(dm: DownloadManager())
}
.navigationViewStyle(DoubleColumnNavigationViewStyle())
.tabItem {
Image(systemName: (selected == 2 ? "photo.fill" : "photo"))
Text("Galleria")
}.tag(2)
NavigationView {
FavoritesView()
}
.navigationViewStyle(DoubleColumnNavigationViewStyle())
.tabItem {
Image(systemName: (selected == 3 ? "star.fill" : "star"))
Text("Preferiti")
}.tag(3)
NavigationView {
InfoView()
}
.navigationViewStyle(StackNavigationViewStyle())
.tabItem {
Image(systemName: (selected == 4 ? "info.circle.fill" : "info.circle"))
Text("Informazioni")
}.tag(4)
}
.accentColor(.white)
.onAppear() {
UINavigationBar.appearance().barTintColor = UIColor(red: 112.0/255.0, green: 90.0/255.0, blue: 143.0/255.0, alpha: 1.0)
UITabBar.appearance().barTintColor = UIColor(red: 112.0/255.0, green: 90.0/255.0, blue: 143.0/255.0, alpha: 1.0)
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
}
}
}
谢谢!
解决方案
推荐阅读
- pointers - 在 C++ 中取消引用 nullptr 警告
- java - Java - 无法使用 selenium 获得最新的 Edge/Chromium 版本
- c# - ComboBox SelectedIndexChanged 事件未触发
- node.js - Viber Bot 从缓冲区发送文件
- algorithm - NN 与贪婪搜索
- python - 在文本文件中搜索和替换字符串
- r - 如何更改 scale_fill_gradient2 的图例标题?
- excel - 如何在 Visual Basic 中调用 API?
- ruby-on-rails - 安装letsencrypt后rails服务器不工作
- javascript - Javascript“基本”和小数错误结果