【发布时间】:2021-01-19 09:37:02
【问题描述】:
我尝试为我的应用程序创建字体扩展,如下所示:
import SwiftUI
extension Font {
// H1
static var largeTitle: Font {
return Font.custom("Roboto-Bold", size: 34)
}
// H2
static var title: Font {
return Font.custom("Roboto-Bold", size: 24)
}
// Body 2 (input title)
static var caption: Font {
return Font.custom("Roboto-Regular", size: 14)
}
...
字体在模拟器中正确应用。但实时预览崩溃并在诊断窗口中出现以下错误
ambiguous use of 'caption'
----------------------------------------
CompileDylibError: Failed to build LoginView.swift
Compiling failed: ambiguous use of 'caption'
/src/Login/LoginView.swift:31:31: error: ambiguous use of 'caption'
.font(Font.caption)
^
/src/Font.swift:38:16: note: found this candidate
static var caption: Font {
^
SwiftUI.Font:14:23: note: found this candidate
public static var caption: Font
我做错了吗?有办法解决吗?
【问题讨论】:
标签: ios swift xcode swiftui live-preview