修复警告:无法在 (Project.UnderlinedTextField) 上设置 (lineColor) 用户定义的检查 属性

Fix warning: Failed to set (lineColor) user defined inspected property on (Project.UnderlinedTextField)

我不断收到此警告:

2020-08-22 17:33:31.484454-0500 bob-app-ios[95799:7064579] 
Failed to set (lineColor) user defined inspected property on 
(projectName.UnderlinedTextField): [<projectName.UnderlinedTextField 0x7fbca5084e00> 
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key lineColor.

当运行我的项目在模拟器中时,这是我的UnderlinedTextField class:

import UIKit

class UnderlinedTextField: UITextField {
    var isWriting = false
    let bottomLine = CALayer()
    
    func underlined() {
        self.delegate = self
        
        let width = CGFloat(1.0)
        reloadUnderlinedTextField()
        bottomLine.frame = CGRect(x: 0, y: self.frame.size.height - width, width:  self.frame.size.width, height: self.frame.size.height)
        bottomLine.borderWidth = width
        self.layer.addSublayer(bottomLine)
        self.layer.masksToBounds = true
    }
    
    func reloadUnderlinedTextField() {
        bottomLine.borderColor = isWriting ? ColorManager.PrimaryColor?.cgColor : ColorManager.Gray500?.cgColor
    }
}

extension UnderlinedTextField: UITextFieldDelegate {
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let maxLength = 1
        let currentString: NSString = (textField.text ?? "") as NSString
        let newString: NSString =
            currentString.replacingCharacters(in: range, with: string) as NSString
        return newString.length <= maxLength
    }
    
    func textFieldDidBeginEditing(_ textField: UITextField) {
        isWriting = true
        reloadUnderlinedTextField()
    }
    
    func textFieldDidEndEditing(_ textField: UITextField) {
        isWriting = false
        reloadUnderlinedTextField()
    }
}

我应该担心吗?我该如何解决?

我也收到这个警告:

2020-08-22 17:33:32.683970-0500 projectName[95799:7064579] Can't find keyplane that supports type 4 
for keyboard iPhone-PortraitChoco-NumberPad; using 25752_PortraitChoco_iPhone-Simple-Pad_Default

我的应用程序没有崩溃,但我觉得应该处理这些警告,因此,我们将不胜感激任何帮助。

据我所知,您无法消除此警告

2020-08-22 17:33:32.683970-0500 projectName[95799:7064579] Can't find keyplane that supports type 4 
for keyboard iPhone-PortraitChoco-NumberPad; using 25752_PortraitChoco_iPhone-Simple-Pad_Default

关于 lineColor,您需要 select 故事板中的 UnderlinedTextField 并从中删除 lineColor 属性 ->

我几乎可以肯定你会在那里找到它

如果您希望在 UnderlinedTextField 上使用 lineColor,则需要添加以下代码

@IBInspectable var lineColor: UIColor? {
    didSet {
        //do something here
    }
}

当应用于 UIView 或 NSView subclass 时,您还需要在 class 上方添加 @IBDesignable 名称,因为它允许 Interface Builder知道它应该直接在 canvas 中呈现视图。这允许在每次更改后查看您的自定义视图将如何显示而无需构建和 运行 您的应用程序。 More details can be found here

如果在 UnderlinedTextField 上不需要 lineColor,那么:

  1. xib(s) 中搜索 (⌘ + ⇧ + F) lineColor故事板
  2. 找到您将 class UnderlinedTextField 分配给的位置 UITextfield 转到身份检查器
  3. 删除用户定义运行时间属性
  4. 下的线条颜色
  5. 构建并运行

关于第二个警告请visit here.