Picker with SegmentedPickerStyle and Image

Hello,

I have a problem for SegmentedPickerStyle-Picker using Images. Default style is ok, but scaledToFit does not work in SegmentedPickerStyle.

Do I have something to do?

Thanks.

Code Block Swift
Picker(selection: $selection, label: EmptyView()) {
        Image("image0")
          .resizable()
          .scaledToFit()
          .tag(0)
         
        Image("image1")
          .resizable()
          .scaledToFit()
          .tag(1)
}
.pickerStyle(DefaultPickerStyle())
//.pickerStyle(SegmentedPickerStyle())

Accepted Reply

Well, you did not say what the exact problem was. I thought you did not see the image, in fact it is not displayed properly.

In fact it appears that scaleToFit does nothing !
https://stackoverflow.com/questions/59635519/swiftui-picker-segmentedstyle-image-bad-display

Should file a bug report.

Note: that is the same problem than in UIKit TabBar icons. You have to manually size the image before using.

Thanks to note the FB reference if you file a bug report. And don't forget to close the thread.

Replies

Could you try with this:
Code Block
Image(uiImage: UIImage(imageLiteralResourceName: "image0"))
.resizable()
.scaledToFit()
.tag(0)


This pattern works for me ; but Image("image0") does not show anything.

Don't forget to close the thread if that's OK.
Thank you for your reply, but this did not work.
Nothing changed. Each image is square, but it becomes a horizontally long rectangle.

Code Block Swift
Image(uiImage: UIImage(imageLiteralResourceName: "image0"))

Well, you did not say what the exact problem was. I thought you did not see the image, in fact it is not displayed properly.

In fact it appears that scaleToFit does nothing !
https://stackoverflow.com/questions/59635519/swiftui-picker-segmentedstyle-image-bad-display

Should file a bug report.

Note: that is the same problem than in UIKit TabBar icons. You have to manually size the image before using.

Thanks to note the FB reference if you file a bug report. And don't forget to close the thread.
Thank you for your information. I can avoid this trouble with the method the linked-page says.
I also submitted a bug report (feedback).