我正在学习有关 Swift UI 的教程,我是新手,我尝试了以下代码,但遇到了一个我无法理解的错误。
代码在教程中运行良好,看起来像新视频,但不是那么旧,这是代码
import SwiftUI
struct ContentView: View {
var body: some View {
ZStack {
// Color(red: 1.00, green: 0.89, blue: 0.00)
// .edgesIgnoringSafeArea(.all)
VStack {
Image("pp")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: CGFloat(150.0), height: CGFloat(150.0))
.clipShape(Circle())
.overlay(
Circle().stroke(Color.white, lineWidth: CGFloat(5.0))
)
Text("John Doe")
.font(Font.custom("AdventPro-Regular", size: 40))
.bold()
.foregroundColor(.black)
Text("Web & iOS Developer")
.font(.Font.custom("AdventPro-Regular",size: 25))
.foregroundColor(.black)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
最佳答案
代替
.font(.Font.custom("AdventPro-Regular",size: 25)) // << .Font is error
使用
.font(Font.custom("AdventPro-Regular",size: 25))
编译器有时无法检测到 SwiftUI 代码的正确错误位置,要在您的 View 构建器中找到真正的错误位置,请尝试注释掉部分代码 - 这会有所帮助。
关于ios - 无法推断通用参数 'S',对图像使用 clipShape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59589903/