1.實(shí)現(xiàn)輸入手機(jī)號(hào)碼間隔顯示
@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!)
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者