swift - 在 SwiftUI 中仅显示图像的顶部
问题描述
我需要以仅显示图像顶部的方式对齐 UIImageView。
原始图像:-
我从下面的代码中获得了图像:-
代码:-
Image("ImageDemo")
.resizable()
.scaledToFill()
.frame(height: 120, alignment: .center)
.clipped()
.cornerRadius(20, corners: [.topLeft, .topRight])
.padding(.bottom)
有人可以向我解释如何仅显示顶部的图像,我已尝试按上述方式实现,但还没有结果。
任何帮助将不胜感激。
提前致谢。
解决方案
使用alignment: .top
它将解决您的问题。
struct ContentView: View {
var body: some View {
Image("Your Image Here!")
.resizable()
.scaledToFill()
.cornerRadius(20)
.frame(height: 120, alignment: .top) // <<: Here
.clipped()
.padding()
}
}
推荐阅读
- node.js - 如何使用 Node.js 和 Handlebars 禁用按钮?
- php - html日期输入-> php-> sql不工作
- php - 如何使用 PHP 获取社交网络 URL 的元数据
- android - 使用 ConstraintLayout 创建底部工作表对话框
- asp.net-core - ASP.NET Core NuGET 包 Microsoft.AspNetCore.Hosting 2.2.7 版是 ASP.NET Core 5.0 的一部分吗?
- firebase - 如何使用 Firebase 函数 + NestJS + Fastify?
- c++ - Microsoft C/C++:“严格一致性”wrt 实现的定义是什么?
- mlops - Triton 推理服务器:显式模型控制
- python - 导入包时不允许操作
- c - C 到 Fotran:指向 char 数组的 C 指针的互操作性,在结构中声明