【问题标题】:Fix warning: Failed to set (lineColor) user defined inspected property on (Project.UnderlinedTextField)修复警告:无法在 (Project.UnderlinedTextField) 上设置 (lineColor) 用户定义的检查属性
【发布时间】:2020-12-11 23:03:42
【问题描述】:

我不断收到此警告:

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

我的应用没有崩溃,但我觉得应该注意这些警告,因此,非常感谢任何帮助。

【问题讨论】:

    标签: ios swift uitextfield uistoryboard


    【解决方案1】:

    如果您希望 UnderlinedTextField 上出现 lineColor,那么您需要添加以下代码

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

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

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

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

    第二个警告请visit here.

    【讨论】:

      【解决方案2】:

      据我所知,您无法关闭此警告

      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 属性 ->

      我几乎确定你会在那里找到它

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-25
        • 2020-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-19
        • 1970-01-01
        相关资源
        最近更新 更多