首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SwiftUI镜像clipsToBounds

SwiftUI镜像clipsToBounds
EN

Stack Overflow用户
提问于 2019-06-30 21:40:54
回答 3查看 16.7K关注 0票数 34

在尝试使用SwiftUI (Xcode11.0beta2)时,我尝试用图像填充视图:

代码语言:javascript
复制
Image("large")
    .resizable()
    .aspectRatio(contentMode: .fill)
    .frame(width: 80, height: 80, alignment: .center)
    .border(Color.black)

如下所示:

我想应用类似于UIView.clipsToBounds的东西,这样图像就被剪裁了,盒子外面的部分就看不见了。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-06-30 21:46:31

您可以使用.clipped()修饰符,其效果与UIView.clipsToBounds类似

代码语言:javascript
复制
Image("large")
    .resizable()
    .aspectRatio(contentMode: .fill)
    .frame(width: 80, height: 80, alignment: .center)
    .border(Color.black)
    .clipped() // Equal to clipsToBounds = true
票数 50
EN

Stack Overflow用户

发布于 2019-07-04 13:35:37

代码语言:javascript
复制
Image("large")
   .resizable()
   .clipShape(Circle())
   .frame(width: 200.0, height: 200.0)
   .overlay(Circle().stroke(Color.white,lineWidth:4).shadow(radius: 10))

票数 22
EN

Stack Overflow用户

发布于 2021-03-24 09:37:47

代码语言:javascript
复制
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)
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56825294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档