swift - 更改图像形状后,SwiftUI 无法编译
问题描述
我对以前的设计不满意,所以我想稍微更改一下代码,但是当我尝试下面的代码时,它开始给我一个错误。Swift UI 错误处理不是最好的,所以我不知道如何修复它
这是代码
struct spanishfood: View {
@State private var stack1 =
[Image("spanish_omelette"),
Image("paella"),
Image("gazpacho"),
Image("patatas_bravas")]
@State private var names =
[Text("Spanish Omelette"),
Text("Paella"),
Text("Gazpacho"),
Text("Patatas Bravas")]
var views =
[AnyView(spanish_omelette()),
AnyView(paella()),
AnyView(gazpacho()),
AnyView(patatas_bravas())]
var body: some View {
GeometryReader { geometry in
ScrollView {
VStack(spacing: 10) {
Text("Spanish Food")
.font(.title)
.font(Font.system(size: 36, design: .serif))
.foregroundColor(.black)
.fontWeight(.thin)
.bold()
.italic()
.kerning(5)
.background(Color.white.opacity(0.6))
.shadow(radius: 31)
ForEach(0..<self.stack1.count) { index in
NavigationLink(destination: self.views[index]) {
VStack(spacing: 10) {
self.stack1[index]
.resizable()
.renderingMode(.original)
.frame(width: UIScreen.screenWidth, height: 300)
.clipShape(RoundedRectangle())
self.names[index].foregroundColor(.white)
.bold()
}.animation(.interpolatingSpring(stiffness: 50, damping: 1))
}
}
}.frame(width: geometry.size.width)
}
}
}
}
以前的形状是圆形的,框架要小得多
解决方案
通过代码阅读 this .clipShape(RoundedRectangle())
,因为RoundedRectangle
没有空参数构造函数。可能的修复如下
.clipShape(RoundedRectangle(cornerRadius: 12))
推荐阅读
- javascript - Javascript 字母加扰/冲突脚本的问题
- javascript - 带有自增徽章的 React js favicon
- javascript - 如何在没有画布的情况下内联加载葡萄 JS?
- python - 当服务器上没有剩余 RAM 时,keras cusom fit 函数崩溃
- javascript - 引导卡堆叠效果
- c - 如何使用 fgetpwent()
- r - R randomForestSRC:如何提取(或计算)解释的方差?
- excel - 如何在excel中设置自定义格式?
- aem - AEM | 为什么 Sling ContentDistribution 事件不提供 deepPaths 事件属性?
- spring-security - 在多租户 stup 中使用 Spring Security OAuth 动态注册 OIDC 客户端