Hi All,
Very new to Swift here. I have a very simple UISegmentedControl where I have set the image for each segment.
segmentedControl.setImage(UIImage(named: “cat”), forSegmentAt: 0)
segmentedControl.setImage(UIImage(named: “dog”), forSegmentAt: 1)
Now that I have the image set, I wanted to change the tintColor to blue for the selected segment and gray for the unselected segment. Below is the code that I was using.
for i in 1…segmentedControl.subviews.count {
let index = i - 1
segmentedControl.subviews[index].tintColor = ( segmentedControl.selectedSegmentIndex == index ? UIColor.blue : UIColor.gray)
}
The problem I am experiencing is that the selected segment’s image is always white. I am not sure why this is even the case as I did not specify the tintColor as white. Can anyone see what I am doing wrong? Thanks.
John