首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.font不能转换为.font

.font不能转换为.font
EN

Stack Overflow用户
提问于 2019-07-12 06:36:06
回答 1查看 280关注 0票数 2

我正在学习Swift UI教程,我遇到了这个错误,而讲师没有。.font错误在第一个Vstack中只出现一次,而第二次没有问题。

代码语言:javascript
复制
import SwiftUI

struct ContentView : View {
    @State var title: String = ""
    @State var rating = 3.0
    @State var seen = false

    var body: some View {
        List {
            Section {
                VStack(alignment: .leading) {
                    Text("Title")
                    .font(.subheadline)       
                    .foregroundColor(.grey)
                TextField($title)
                }
            }
            Section {
                VStack(alignment: .leading) {
                    Text("Rating").font(.subheadline)
                    .foregroundColor(.gray)
                    HStack {
                        Spacer()
                    Text(String(repeating:"*", count:Int(rating)))
                Slider(value: $rating, from: 1.0, through: 5.0, by: 
        1.0).font(.title)
                        .foregroundColor(.yellow)
                    Spacer()
                    }
                }
            }

         }.listStyle(.grouped)
       }
    }

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif
代码语言:javascript
复制
Tracker/ContentView.swift:22:28: 'Font' is not convertible to 
'Font?'
EN

回答 1

Stack Overflow用户

发布于 2019-07-12 07:15:44

这是一个误导性的错误。这个问题与Font没有任何关系。问题是你有一个打字错误:

代码语言:javascript
复制
Text("Title")
    .font(.subheadline)       
    .foregroundColor(.grey)

foregroundColor应为.gray,而不是.grey

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56998118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档