SwiftUI: 用非系统图来处理tabView

import SwiftUI

struct ContentView: View {
    @State private var selection = 3
    
    var body: some View {
        TabView (selection:$selection){
            Text("Tab Content 1").tabItem {
                Text("图表")
                Image(selection == 1 ? "chart_icon" : "chart_icon_gray")
                }.tag(1)
                        
                Text("Tab Content 2").tabItem { Text("账户")
                    Image(selection == 2 ? "account_icon" : "account_icon_gray")
                }.tag(2)
                TurnOverView().tabItem {
                    Text("流水")
                    Image(selection == 3 ? "turnover_icon" : "turnover_icon_gray")
                }.tag(3)
                Text("Tab Content 4").tabItem { Text("预算")
                    Image(selection == 4 ? "budget_icon" : "budget_icon_gray")
                }.tag(4)
                Text("Tab Content 5").tabItem { Text("我的")
                    Image(selection == 5 ? "mine_icon" : "mine_icon_gray")
                }.tag(5)
        }.accentColor(Color.black)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

你可能感兴趣的:(SwiftUI: 用非系统图来处理tabView)