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

问题描述

我不断收到此警告:

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类:

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

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

解决方法

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

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

当应用于UIView或NSView子类时,还需要在类上方添加 @IBDesignable 标识,因为它使Interface Builder知道应直接在画布中呈现视图。这样一来,您无需更改每次构建后即可运行您的应用,即可查看自定义视图的显示方式。 More details can be found here

如果您不需要 UnderlinedTextField 上的 lineColor ,则:

    xib Storyboard
  1. 搜索(⌘+⇧+ F )中的 lineColor 。 >
  2. 找到将类 UnderlinedTextField 分配给的位置 UITextfield(s) 转到身份检查器
  3. 用户定义的运行时属性
  4. 下删除lineColor
  5. 构建并运行

enter image description here

关于第二次警告,请visit here.

,

据我所知,您不能沉默此警告

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,您需要在Storyboard中选择UnderlinedTextField并从此菜单项中删除lineColor属性-> enter image description here

我几乎可以肯定您会在其中找到