reports icon indicating copy to clipboard operation
reports copied to clipboard

FB13659840: Unable to add a color(tintColor) to each TabItem in the TabView.

Open zunda-pixel opened this issue 11 months ago • 0 comments

  • Date: 2024-2-28
  • Resolution: Open
  • Area: SwiftUI
  • OS: iOS
  • Type: Incorrect/Unexpected Behavior
  • Keywords: SwiftUI, TabView

Details

Unable to add a color(tintColor) to each TabItem in the TabView.

enum TabItem: String, CaseIterable {
  case first
  case second
  case third
  
  var tabColor: Color {
    switch self {
    case .first: .red
    case .second: .blue
    case .third: .green
    }
  }
}

struct TestView: View {
  var body: some View {
    TabView {
      ForEach(TabItem.allCases, id: \.self) { tab in
        Text(tab.rawValue)
          .tabItem {
            Label(tab.rawValue, systemImage: "bird")
              .tint(tab.tabColor)
          }
      }
    }
    .tint(.yellow)
  }
}

zunda-pixel avatar Feb 27 '24 17:02 zunda-pixel