swiftui - 图像集框架
问题描述
在 SwiftUI 的官方教程中,我尝试自定义图像以显示整个屏幕
解决方法是将框架设置为固定的宽度和高度
struct CircleImage : View {
var body: some View {
Image("image01")
// .frame(width: 300, height: 300)
.clipShape(Circle())
.overlay(
Circle().stroke(Color.white, lineWidth: 4))
.shadow(radius: 10)
}
}
struct ContentView : View {
var body: some View {
VStack {
MapView()
.edgesIgnoringSafeArea(.top)
.frame(height: 300)
CircleImage()
.offset(y: -130)
.padding(.bottom, -130)
.frame(width: 300, height: 300)
VStack(alignment: .leading) {
Text("Hello Maxwell!")
.font(.title)
HStack(alignment: .top) {
Text("Chaoyang Beijing")
.font(.subheadline)
Spacer()
Text("China")
.font(.subheadline)
}
}
.padding()
Spacer()
}
}
}
为什么 ContentView call.frame(width: 300, height: 300) 无效?
解决方案
我假设当你说“无效”时,你的意思是图像没有调整到宽度和高度为 300 的框架。如果是这样,你的问题是你没有使图像调整大小。更新CircleImage
下面的代码,图像应该调整大小。
struct CircleImage : View {
var body: some View {
Image("image01")
.resizable() //add this line
.clipShape(Circle())
.overlay(
Circle().stroke(Color.white, lineWidth: 4))
.shadow(radius: 10)
}
}
推荐阅读
- python - Django - 在创建用户时对配置文件执行操作
- python - 如何正确关闭包含 matplotlib 动画图表的 tk.Toplevel
- reactjs - 将 .NET Core 3.1 Web API 与 React App 集成为 MVC 应用程序
- javascript - 如何从动态复选框中选择单个复选框
- apache-spark - EMR-5.32.0 上的 Spark 未生成请求的执行程序
- jsf - 如何重置 PrimeFaces 动态列的排序?
- sql-server - 包含嵌套对象的 XML 存在问题到 POCO(反)序列化(VB.Net)
- python - 获取TypeError:**或pow()不支持的操作数类型:'builtin_function_or_method'和'int'在Python中求解方程时
- postgresql - 编写一个触发器函数以根据 postgresql 中同一表中的另一个列值更新列值
- typo3 - TYPO3 9.5 扩展生成器抛出异常