Change Segmented Picker Tint Color On Click

Does anyone know how to achieve this? I have four colors of red, green, yellow, and blue and I want my selected segment to have a background/tint color that is indicative of the color name.

This is my code:
Code Block
let objectColors = Color.allCases
@State private var selectedColorIndex = 0
//declared in body view.../
Picker("Colors", selection: $selectedColorIndex)
{ForEach(0..<objectColors.count){ index in
Text(self.objectColors[index].rawValue).tag(index)
}
}
.pickerStyle(SegmentedPickerStyle())
.padding(10)
.onAppear{
UISegmentedControl.appearance().selectedSegmentTintColor = UIColor.generateUIColor(colorIndex: selectedColorIndex) 
}

This is the list I'm pulling from
Code Block
enum Color: String, CaseIterable{case red, yellow, green, blue}

I've tried using onChange or onReceive (together with Combine's 'Just()' for subview) instead of onAppear but they crash on playgrounds and don't work on Xcode. onTapGesture doesn't seen to work too

I also saw a WWDC video on UIAction that I think will work great for updating the picker view changes but I have no idea how to translate it. Does anyone one have any suggestions or help, please? Thanks
Change Segmented Picker Tint Color On Click
 
 
Q