如何在swiftUI中拉伸图像的一侧,就像Android中的.9文件?

问题描述 投票:0回答:1

我有一张图片,我只想拉伸它的高度以适合不同的内容,我该如何在swiftUI中做到这一点?

Image("rightTag")
    .resizable()
    .aspectRatio(contentMode: .fit)
    .frame(maxWidth: 20)

粗略的可调整大小,无法完成。任何帮助都会很棒!谢谢!

swiftui
1个回答
0
投票

我不确定我是否正确理解了您的目标,但似乎像下面这样

Image("auto") // << your image here
    .resizable()
    .aspectRatio(contentMode: .fill)
    .frame(maxWidth: 20, alignment: .leading) // ?? not sure about alignment for you, 
                                              // but this gives left-size 20 pt of image
    // .clipped() // << uncomment if needed
© www.soinside.com 2019 - 2024. All rights reserved.