스위프트 3에서 스위프트 4로 프로젝트를 이전했으며 글꼴 속성을 얻는 방법을 UIFontDescriptor
에서 찾을 수 없습니다. swift에서 글꼴 속성 가져 오기
@objc convenience init(myCoder aDecoder: NSCoder) {
if let fontDescriptor = aDecoder.decodeObject(forKey: "UIFontDescriptor") as? UIFontDescriptor {
if let fontAttribute = fontDescriptor.fontAttributes["NSCTFontUIUsageAttribute"] as? String {
var fontName = ""
switch fontAttribute {
case "CTFontRegularUsage":
fontName = Roboto.regular.rawValue
case "CTFontEmphasizedUsage", "CTFontBoldUsage":
fontName = Roboto.bold.rawValue
default:
fontName = Roboto.regular.rawValue
}
self.init(name: fontName, size: fontDescriptor.pointSize)!
}
else {
self.init(myCoder: aDecoder)
}
}
else {
self.init(myCoder: aDecoder)
}
}
그러나 빠른 4 라인에서
가 :if let fontAttribute = fontDescriptor.fontAttributes["NSCTFontUIUsageAttribute"] as? String
에 오류가 있습니다 : 여기에 빠른 3에서 완벽하게 작동하는 코드입니다 Ambiguous reference to member 'subscript'
. 아이디어를 어떻게 변경할 수 있습니까?
감사합니다!
을 여기에 워드 프로세서는, 스위프트 4 변경 사항이 강조 표시됩니다. 아무것도 주목 해? https://developer.apple.com/documentation/uikit/uifontdescriptor?changes=latest_minor – matt
또한 무엇을하려하십니까? 사용자 정의 글꼴로 동적 유형을 지원하려는 경우 완전히 새로운 방식으로 지원됩니다. https://developer.apple.com/documentation/uikit/uifontmetrics – matt
@noname, 문제 해결 방법을 알려주십시오. – Rbar