美文网首页
Swift学习记录

Swift学习记录

作者: 404该页面无法显示 | 来源:发表于2017-07-14 16:47 被阅读4次
    1.实现输入手机号码间隔显示
    手机号码间隔显示
      @objc func transformToPhoneNumber() {
            let textStr = textField.text
            var termStr = textStr?.replacingOccurrences(of: " ", with: "")
            if (termStr?.characters.count)! < 12 {
                if (termStr?.characters.count)! > 7 {
                    let secondIndex = termStr?.index((termStr?.startIndex)!, offsetBy: 7)
                    termStr?.insert(" ", at: secondIndex!)
                }
                if (termStr?.characters.count)! > 3 {
                    let firstIndex = termStr?.index((termStr?.startIndex)!, offsetBy: 3)
                    termStr?.insert(" ", at: firstIndex!)
                }
            }
            textField.text = termStr
            print(termStr!)
      }
    

    相关文章

      网友评论

          本文标题:Swift学习记录

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