能否将LinearGradient应用于TabItem? AccentColor只需要一种颜色,我没有找到其他方法来将任何颜色应用于TabItem。 有什么想法吗?
能否将LinearGradient应用于TabItem? AccentColor只需要一种颜色,我没有找到其他方法来将任何颜色应用于TabItem。 有什么想法吗?
struct ContentView: View {
@State var selection = 0
var body: some View {
TabView(selection: $selection) {
Text("First")
.tabItem {
Image(selection == 0 ? "home_active" : "home_inactive") //<< here you load your different images
Text("Home")
.colorMultiply(Color.yellow)
}
Text("Second")
.tabItem {
Image(selection == 1 ? "setting_active" : "setting_inactive")
Text("Setting")
}
}
}
}
是的,在SwiftUI中我们无法在tabItem上应用渐变。它只会显示一个图像和一个文本视图,即使我们已经在.tabItem{}中放置了更多的视图。
因此,您必须制作自定义选项卡栏。