setValue:forUndefinedKey:这个类不符合ios12中键boldColor的键值编码



我有这个自定义标签,我在我的应用程序中使用,但当我在ios 12的设备上运行我的应用程序时,它崩溃了这个错误NSUnknownKeyException', reason: '[<EFontRegular 0x10999e050> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key boldColor但在ios 13及以上版本中运行良好。任何帮助都将不胜感激。网上所有其他的解决方案都不适合我

@IBDesignable
final class EFontRegular: BaseUILabel {
override var fontType: UIFont? {
return UIFont(name: EFontConstant.Name.regular.rawValue, size: fontSize)
}
}
@IBDesignable
class BaseUILabel: UILabel {

@IBInspectable var fontSize: CGFloat {
return self.font.pointSize
}

@IBInspectable var fontType: UIFont? {
return UIFont(name: EFontConstant.Name.regular.rawValue, size: EFontConstant.Size.regular.rawValue)
}

@IBInspectable var stringToColor: String = "" {
didSet {
let alignment: NSTextAlignment = alignCenter ? .center : .left
attributedText = text?.lineSpacedWithInlineColor(lineSpacing, alignment, stringToColor: stringToColor)
}
}

@IBInspectable var boldColor: UIColor {
traitCollection.userInterfaceStyle == .light ? .black : .white
}

@IBInspectable var stringToBold: String = "" {
didSet {
let alignment: NSTextAlignment = alignCenter ? .center : .left
attributedText = text?.lineSpacedWithInlineColor(lineSpacing, alignment, stringToColor: stringToBold, color: boldColor, bold: true, boldTextSize: fontSize)
}
}

override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}

override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
commonInit()
}

}

我也有同样的问题,我通过删除不需要的或额外的连接来解决这个问题,你没有在故事板中使用。对我来说,这个错误通常发生在我从一个项目中复制所有的故事板并将它们粘贴到新项目中,并更改组件名称和操作,但忘记删除故事板中UI组件的旧名称和操作时。这样的

最新更新