【问题标题】:Narrowing Down UITextField on BackSpace while typing键入时缩小 BackSpace 上的 UITextField
【发布时间】:2016-05-09 15:39:55
【问题描述】:

使用 Storyboard,我设置了一个 UITextField 和两个静态 UILabel。我设置了约束,以便静态标签在 TextField 中作为用户类型展开。

       [Label1] [TextField] [Label2]

[Label1] [TextFieldIsGettingFilled] [Label2]

到目前为止一切都很好。当用户输入时,TextField 变得越来越宽。但是,如果用户使用退格(删除字符),TextField 不会变窄。所以它变成了:

[Label1] [TextField         ] [Label2] 

当用户仍在打字时,检测退格并相应缩小 TextFields 宽度的方法是什么?

【问题讨论】:

    标签: ios swift autolayout uitextfield uitextfielddelegate


    【解决方案1】:

    编辑

    我做了一个例子,这很有效(根据文本增加和减少):

    func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
        textField.invalidateIntrinsicContentSize()
        return true
    }
    

    来源:Resize a UITextField while typing (by using Autolayout)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-28
      • 2010-10-02
      • 1970-01-01
      • 2011-02-14
      • 1970-01-01
      相关资源
      最近更新 更多