UITextfield响应返回UIViewNoIntrinsicMetric

时间:2017-12-29 19:15:49

标签: ios swift uitextfield

我已将UITextfield添加到视图中,但是当我运行应用并按下文本字段时,我会收到以下错误:

error: <_UIKBCompatInputView: 0x7fedd4c1b8e0; frame = (0 0; 0 0); 
layer = <CALayer: 0x6040004293c0>> returned 0 width, assuming 
UIViewNoIntrinsicMetric

是什么导致这种情况发生?

自定义UIView代码

    let rightBottomView = UIView()
    rightBottomView.isUserInteractionEnabled = true
    rightBottomView.translatesAutoresizingMaskIntoConstraints = false
    self.bottomView.addSubview(rightBottomView)


    bottomValueField = UITextField()
    bottomValueField.tag = 1
    bottomValueField.tintColor = UIColor(hex: "#6AAFFF")
    bottomValueField.translatesAutoresizingMaskIntoConstraints = false
    bottomValueField.delegate = self
    bottomValueField.textColor = Color.lightTheme.value
    bottomValueField.font = UIFont(name: "Avenir-Medium", size: 26)
    bottomValueField.attributedPlaceholder = NSAttributedString(string: "0", attributes: [NSAttributedStringKey.foregroundColor: Color.lightTheme.value])
    bottomValueField.textAlignment = .right
    rightBottomView.addSubview(bottomValueField)

    rightBottomView.centerYAnchor.constraint(equalTo: bottomView.centerYAnchor).isActive = true
    rightBottomView.leftAnchor.constraint(equalTo: leftBottomView.rightAnchor).isActive = true
    rightBottomView.rightAnchor.constraint(equalTo: self.rightAnchor, constant: -24).isActive = true
    rightBottomView.heightAnchor.constraint(equalToConstant: 60).isActive = true
    rightBottomView.widthAnchor.constraint(equalTo: leftBottomView.widthAnchor).isActive = true

    bottomValueField.centerYAnchor.constraint(equalTo: rightBottomView.centerYAnchor).isActive = true
    bottomValueField.centerXAnchor.constraint(equalTo: rightBottomView.centerXAnchor).isActive = true
    bottomValueField.heightAnchor.constraint(equalTo: rightBottomView.heightAnchor).isActive = true
    bottomValueField.widthAnchor.constraint(equalTo: rightBottomView.widthAnchor).isActive = true

0 个答案:

没有答案