3
ここにカスタムフォントを初期化しようとしていますが、エラーを示しています。swift 4:タイプ '[UIFontDesciptor.AttributeName:Any]'のインデックスに 'String'タイプのインデックスを添字できません
extension UIFont {
@objc convenience init(myCoder aDecoder: NSCoder) {
if let fontDescriptor = aDecoder.decodeObject(forKey: "UIFontDescriptor") as? UIFontDescriptor {
if let fontAttribute = fontDescriptor.fontAttributes["NSCTFontUIUsageAttribute"] as? String { // HERE SHOWING THE ERROR
var fontName = ""
switch fontAttribute {
case "CTFontRegularUsage":
fontName = appFontName
case "CTFontEmphasizedUsage", "CTFontBoldUsage":
fontName = appFontBoldName
case "CTFontObliqueUsage":
fontName = appFontItalicName
default:
fontName = appFontName
}
self.init(name: fontName, size: fontDescriptor.pointSize)!
}
else {
self.init(myCoder: aDecoder)
}
}
else {
self.init(myCoder: aDecoder)
}
}
...
}
これはswift-3.2に完全に対応しています。しかし、それは迅速な4.0で実行されていません。私を助けてください。前もって感謝します。
を書くことができる利点は、それが私の作品です! –