gpt4 book ai didi

ios - 如何在 FPNTextField 中检测国家代码和更改标志

转载 作者:行者123 更新时间:2023-12-04 08:55:59 27 4
gpt4 key购买 nike

我正在使用 FlagPhoneno Pod 使用以下代码搜索或选择带有标志的国家代码。但是当谈到编辑部分时,我得到了 FPNtextFeild ex-+971568573570 的完整电话号码,默认情况下我将国家代码设置为 .AE
当任何其他国家/地区电话无法从 json let recivedPhoneNo = self.json["phone_number"].string ?? "" 获取时,我想检测并自动更改国家/地区标志
目前,仅选择时标志正在更改。请向我展示一个示例方法,其中包含来自同一 pod“FlagPhoneno”模块的代码。
我正在使用以下代码。

    func setupPhoneTF(){
self.phoneTFView.layer.borderColor = UIColor.appColor.customGray.cgColor
self.phoneTFView.layer.cornerRadius = 5
self.phoneTFView.layer.borderWidth = 1

phoneTF.displayMode = .list // .picker by default
listController.setup(repository: phoneTF.countryRepository)

listController.didSelect = { [weak self] country in
self?.phoneTF.setFlag(countryCode: country.code)
}

phoneTF.delegate = self
phoneTF.font = UIFont.systemFont(ofSize: 14)

// Custom the size/edgeInsets of the flag button
phoneTF.flagButtonSize = CGSize(width: 35, height: 35)
phoneTF.flagButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
let items = [
UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.save, target: self, action: nil),
UIBarButtonItem(title: "Item 1", style: .plain, target: self, action: nil),
UIBarButtonItem(title: "Item 2", style: .plain, target: self, action: nil)
]
phoneTF.textFieldInputAccessoryView = getCustomTextFieldInputAccessoryView(with: items)
phoneTF.hasPhoneNumberExample = true
phoneTF.placeholder = "Phone Number"
phoneTF.setFlag(countryCode: .AE)
}

extension AddNewAddressVC: FPNTextFieldDelegate {

func fpnDidValidatePhoneNumber(textField: FPNTextField, isValid: Bool) {
textField.rightViewMode = .whileEditing
textField.rightView = UIImageView(image: isValid ? imageLiteral(resourceName: "success") : imageLiteral(resourceName: "error"))
print(
isValid,
textField.getFormattedPhoneNumber(format: .E164) ?? "E164: nil",
textField.getFormattedPhoneNumber(format: .International) ?? "International: nil",
textField.getFormattedPhoneNumber(format: .National) ?? "National: nil",
textField.getFormattedPhoneNumber(format: .RFC3966) ?? "RFC3966: nil",
textField.getRawPhoneNumber() ?? "Raw: nil"
)
}

func fpnDidSelectCountry(name: String, dialCode: String, code: String) {
print(name, dialCode, code)
self.selectedDialCod = dialCode
}


func fpnDisplayCountryList() {
let navigationViewController = UINavigationController(rootViewController: listController)
listController.title = "Countries"
listController.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .stop, target: self, action: #selector(dismissCountries))
self.present(navigationViewController, animated: true, completion: nil)
}
}

最佳答案

//您可以更改选择的标志然后设置电话号码

phoneNumberTextField.setFlag(for: .FR)
phoneNumberTextField.set(phoneNumber: "0600000001")
//或者直接设置带国家代码的电话号码,会自动更新flag图片
phoneNumberTextField.set(phoneNumber: "+33600000001")

关于ios - 如何在 FPNTextField 中检测国家代码和更改标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63827351/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com