I want make a scrollview inside TabView. but its make a white background color:
im already add .background in TabView its not work.
this is my code for TabView.
*im using my own Image not systemImage.
// DashboardNavigationView.swift
// DevMuscles
//
// Created by Putut Yusri Bahtiar on 05/11/23.
//
import SwiftUI
struct DashboardNavigationView: View {
enum Tab: Int {
case home
case insight
case notifications
case profile
}
@State private var selectedTab = Tab.home
@State private var showNotificationDot = false
var body: some View {
TabView(selection: $selectedTab) {
HomeView()
.tabItem {
selectedTab == Tab.home ? Image("home-active") : Image("home-inactive")
}
.tag(Tab.home)
HomeView()
.tabItem {
selectedTab == Tab.insight ? Image("insight-active") : Image("insight-inactive")
}
.tag(Tab.insight)
HomeView()
.tabItem {
selectedTab == Tab.notifications ? Image("notification-active") : Image("notification-inactive")
}
.tag(Tab.notifications)
Text("Profile")
.tabItem {
Image("profile")
}
.tag(Tab.profile)
}
}
}
#Preview {
DashboardNavigationView()
}
2
Answers
Try setting
.accentColor(.desiredColor)
What you are seeing is the default background for the tab bar when the selected view has a
ScrollView
that goes behind it.You can override the visiblity of the tab bar background by using the modifier
.toolbarBackground
. This modifier needs to be applied to the individual view with theScrollView
inside it, not to theTabView
that contains the view. You can also set aShapeStyle
to be used in place of the default background.Here are some examples: