问题描述
我写的代码可以简单地返回可以这样使用的UIFont
myLabel.font = UIFont.AppleSDGothicNeo.medium.of(20)
实际的实现是这样的
extension UIFont {
enum AppleSDGothicNeo: CustomFont {
var familyName: String {
return "AppleSDGothicNeo-"
}
case thin
case light
case regular
case bold
case semiBold
case ultraLight
case medium
}
}
protocol CustomFont {
var familyName : String { get }
func of(_ size: CGFloat) -> UIFont
}
extension CustomFont {
func of(_ size: CGFloat) -> UIFont {
let name = familyName+String(describing: self)
guard let font = UIFont(name: name,size: size) else {
fatalError("Could not find Custom Font \(self)")
}
return font
}
}
如您所见,我通过使用String(describing: self)
获得了字体名称。如果使用medium
,它将返回带有其familyName
的“ AppleSDGothicNeo-medium”。
但是当我打印出实际的字体名称时,它表示“ AppleSDGothicNeo-Medium”。尽管M
是大写字母,但可以与“ AppleSDGothicNeo-medium”一起使用。
所以.. Swift不在乎字体名称的大写吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)