Swift学习记录
2017-07-14 本文已影响4人
404该页面无法显示
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!)
}