Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI aspectFill

Tags:

ios

swift

swiftui

What is SwiftUI equivalent of UIImageView aspectFill option?

When I do

Image(self.chat.thumbnailName)
.resizable()
.frame(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.width)
.clipped()

(also tried to add .aspectRatio(contentMode: .fill) or .aspectRatio(contentMode: .fit)

I still get an ugly distorted image:

enter image description here

like image 419
Nik Avatar asked Jun 10 '26 22:06

Nik


1 Answers

Use .scaledToFill or .scaledToFit modifiers, per needs. So in your case

Image(self.chat.thumbnailName)
.resizable()
.scaledToFill()
.frame(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.width)
.clipped()
like image 132
Asperi Avatar answered Jun 12 '26 13:06

Asperi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!