【发布时间】:2016-01-04 09:40:55
【问题描述】:
我目前正在尝试覆盖 UIFont 的 systemFontOfSize 方法以返回具有给定字体大小的自定义字体。我的代码目前如下所示:
extension UIFont
{
class func systemFontOfSize(fontSize: CGFloat) -> UIFont
{
return UIFont(name: "HelveticaNeue", size: 10)!
}
}
但是,我无法覆盖该方法。使用上面显示的代码时,出现以下错误:
"Method 'systemFontOfSize' with Objective-C selector 'systemFontOfSize:' conflicts with previous declaration with the same Objective-C selector"
添加覆盖时,错误是该方法没有覆盖任何东西。 有谁知道如何解决这个问题?
【问题讨论】:
-
你不能覆盖类extension中的方法,只能在子类中。
-
@MartinR 对不起,我同时做了同样的事情......
标签: objective-c swift fonts overriding uifont