我创建了一个结构来让我的字体在全局范围内预缓存:
struct Fonts {
static let avenirRegular = UIFont(name: "AvenirNextCondensed-Regular", size: 14.0)
}
用法...:
xy.font = Fonts.avenirRegular
它告诉我,我的常量是可选的。
Value of optional type 'UIFont?' not unwrapped; did you mean to use '!' or '?'?
为什么它是可选的? AvenirNextCondensed-Regular
是否有可能并非在所有 iOS 设备上都可用?非常感谢您的帮助。
最佳答案
这里的“可选”意味着问题是字体可能不存在(即使我们知道它存在)并且你必须识别它,通过将其设为可选你告诉编译器我知道字体不是部分你的图书馆,但我确信它在那里。
关于ios - 为什么字体是可选的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40461007/