在尝试使用SwiftUI (Xcode11.0beta2)时,我尝试用图像填充视图:
Image("large")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 80, height: 80, alignment: .center)
.border(Color.black)如下所示:

我想应用类似于UIView.clipsToBounds的东西,这样图像就被剪裁了,盒子外面的部分就看不见了。
发布于 2019-06-30 21:46:31
您可以使用.clipped()修饰符,其效果与UIView.clipsToBounds类似
Image("large")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 80, height: 80, alignment: .center)
.border(Color.black)
.clipped() // Equal to clipsToBounds = true发布于 2019-07-04 13:35:37
Image("large")
.resizable()
.clipShape(Circle())
.frame(width: 200.0, height: 200.0)
.overlay(Circle().stroke(Color.white,lineWidth:4).shadow(radius: 10))

发布于 2021-03-24 09:37:47
Use GeometryReader can fix the issue where if the clipped region of the image overlaps a button, that button will NOT work
like this:
GeometryReader { geo in
Image("large")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 80, height: 80, alignment: .center)
.border(Color.black)
}.frame(width: 150, height: hh)https://stackoverflow.com/questions/56825294
复制相似问题