swift - .font 不能转换为 .font
问题描述
我正在学习 Swift UI 教程,但我遇到了这个错误,而讲师没有。.font 错误在第一个 Vstack 中仅发生 1 次,而第二次则没有问题。
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
Tracker/ContentView.swift:22:28: 'Font' is not convertible to
'Font?'
解决方案
这是一个误导性错误。这个问题与Font
. 问题是你有一个错字:
Text("Title")
.font(.subheadline)
.foregroundColor(.grey)
foregroundColor
应该.gray
不是.grey
。_
推荐阅读
- python - Vertically concatenate multiple dataframes
- javascript - 如何更有效地使用 NEXT 按钮
- jquery - How to prevent Rails ujs remote form submit from jumping to top of page?
- json - please help me to loop model and get data from rest api
- macos - Responding to Exposé in MacOS
- json - ERROR: NoSuchMethodError: The method 'toDouble' was called on null. Receiver: null Tried calling: toDouble()
- python - why is this not running correctly? thoughts?
- excel - Looking to import filter criteria from an excel table
- javascript - 是否可以在不使用上下文或事件的情况下向 DialogFlow 代理发送额外数据
- visual-studio - 将对象从一个程序集转换为另一个 cli c++