美文网首页
swift文本框小解

swift文本框小解

作者: 有理想有暴富的小青年 | 来源:发表于2018-05-24 16:14 被阅读17次

    文本框不能用textfield.text.count来计算字符  会造成文本框不能删除

    functextField(_textField:UITextField, shouldChangeCharactersIn range:NSRange, replacementString string:String) ->Bool{

            letproposeLength = (textField.text?.lengthOfBytes(using:String.Encoding.utf8))! - range.length+ string.lengthOfBytes(using:String.Encoding.utf8)

           iftextField.tag==0{

                if proposeLength >5{

                    setToast(str:"不能大于5个字")

                    returnfalse

              }else{

                    returntrue

                }

            }

            return true

        }

    相关文章

      网友评论

          本文标题:swift文本框小解

          本文链接:https://www.haomeiwen.com/subject/vgaekftx.html