微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决修复警告:无法在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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。