ios - 无法推断通用参数 'S',对图像使用 clipShape

标签 ios swift swiftui

我正在学习有关 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/

相关文章:

html - Ios 内容页面上的 Ionic 自动向下滑动

Swift NSData getBytes 逆转

math - 在 swift 中使用 CGFloats 进行数学运算的最佳方法是什么?

在 iOS16 中带有不选择选项的 SwiftUI 选择器

swiftui - 从 SwiftUI 中的导航堆栈中删除屏幕

swift - didSet 没有被 Swift 中的 Array.append() 调用

ios - 谷歌分析不显示 ios 数据

ios - 通过获取 Assets 集合排除 iCloud 共享相册

ios - 从 sqlite 表获取数据时出现问题

ios - ScrollView 中的 CollectionView