[英]SwiftUI: How to set custom view size dynamically
也许是以下的一些变体:
struct CustomView: View {
var body: some View {
HStack(spacing: 10) {
Image(systemName: "heart.fill")
.resizable()
.aspectRatio(1, contentMode: .fit)
Image(systemName: "heart.fill")
.resizable()
.aspectRatio(1, contentMode: .fit)
}.frame(maxWidth: .infinity)
}
}
两个图像保持 1:1 的纵横比,它们之间有 10 个点的间距,但允许使用.frame
修饰符水平增长。
根据需要将Image(systemName: "heart.fill")
替换为所需的图像源。
如果您的源图像资产没有 1:1 的纵横比,请将contentMode
设置为.fill
,并使用.frame(height: ..)
限制HStack
或CustomView
内的CustomView
.frame(height: ..)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.