Quantcast
Viewing all articles
Browse latest Browse all 12141

SwiftUI modify image frame

I have an image that I would like to always use the maximum available width. However the image should have a max height of 500 and should only utilize the height if it will fill it. Currently wide images dont fill the full height but the images frame is still 500 and hence why the text views are far away from the image. When the image is taller the width is not all used. How can I use the correct modifiers for this need?

import SwiftUIimport Kingfisherstruct SwiftUIView: View {    var body: some View {        VStack {            Text("hello")            KFImage(URL(string: "https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg"))                .resizable()                .scaledToFit()                .clipShape(RoundedRectangle(cornerRadius: 15))                .contentShape(RoundedRectangle(cornerRadius: 15))                .frame(maxHeight: 500)                .clipped()            Text("hello")        }        .padding(.horizontal, 20)    }}//image: smaller width, larger height//"https://media.macphun.com/img/uploads/customer/how-to/608/15542038745ca344e267fb80.28757312.jpg?q=85&w=1340"#Preview {    SwiftUIView()}
Current result

Image may be NSFW.
Clik here to view.
Demo


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>