どうも、ちょげ(@chogetarou)です。
TabViewの背景色を設定する方法を紹介します。
方法

TabViewの背景色を設定するには、UITabBar.appearance().backgroundColorを使います。
具体的には、initメソッドやonAppear修飾子で、UITabBar.appearance().backgroundColorに背景色を代入します。
init() {
//背景色を代入
UITabBar.appearance().backgroundColor = backgroundColor
}
UITabBar.appearance().backgroundColorに代入した色が、TabViewの背景色になります。
使用例

struct ContentView: View {
init() {
UITabBar.appearance().backgroundColor = .green.withAlphaComponent(0.3)
}
var body: some View {
VStack {
TabView {
PageView(text: "Home View")
.tabItem {
Image(systemName: "house.fill")
Text("home")
}
PageView(text: "Data View")
.tabItem {
Image(systemName: "folder.fill")
Text("Data")
}
PageView(text: "Person View")
.tabItem {
Image(systemName: "person.fill")
Text("Person")
}
}
}
}
}
コメント