在尝试SwiftUI(Xcode 11.0 beta 2)时,我尝试用图像填充View:
Image("large")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 80, height: 80, alignment: .center)
.border(Color.black)
Run Code Online (Sandbox Code Playgroud)
这样呈现:
我想应用类似的东西,UIView.clipsToBounds以便图像被裁剪并且盒子外面的部分不可见。
小智 26
Image("large")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 80, height: 80, alignment: .center)
+ .contentShape(Rectangle())
+ .clipped()
.border(Color.black)
Run Code Online (Sandbox Code Playgroud)
这帮助我通过图像重叠按钮解决了问题。contentShape() 用于剪辑命中测试区域。Clipped() 正在剪切视图边界内的内容(如其他人提到的)。
Arj*_*tel 22
Image("large")
.resizable()
.clipShape(Circle())
.frame(width: 200.0, height: 200.0)
.overlay(Circle().stroke(Color.white,lineWidth:4).shadow(radius: 10))
Run Code Online (Sandbox Code Playgroud)
您可以使用.clipped()修饰符使与UIView.clipsToBounds
Image("large")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 80, height: 80, alignment: .center)
.border(Color.black)
.clipped() // Equal to clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
916 次 |
| 最近记录: |