FMPhoneTextField 1.0.0

FMPhoneTextField 1.0.0

Saad Albasha 维护。




  • Saad Albasha

FMPhoneTextField

FMPhoneTextField 通过从支持阿拉伯语和英语的语言列表中选择国家,提供了一个简单且易于使用的方式来处理手机号码字段。它还会根据您的选择检测使用 SIM 卡或区域设置(您的选择)来找到当前用户所在的国家。

它与 iOS (9.0 - 13.0) 兼容

预览

重要

支持 Swift 5+

要使用 CocoaPods 在 Swift 5.x 中安装 FMPhoneTextField,请将以下内容添加到您的 Podfile 中

pod 'FMPhoneTextField', '~> 1.0'

安装

  1. 查看安装指南

  2. 更新您的 Podfile 以包括以下内容

    use_frameworks!
    pod 'FMPhoneTextField'
  3. 运行 pod install

  1. 在您的代码中导入 FMPhoneTextField,如下所示:import FMPhoneTextField

定制

根据电话地区或蜂窝网络找出默认国家(必须在初始化之前调用)

countryTextField.setDefaultCountrySearch(to: .locale)

设置国家代码显示(必须在初始化之前调用)

countryTextField.setCountryCodeDisplay(type: .bothIsoShortCodeAndInternationlKey)

在列表中隐藏国家代码

countryTextField.setCountryCodeInList(hidden: false)

FMPhoneDelegate

func didSelectCountry(_ country: CountryElement) {

    //have access on selected country
}

func didGetDefaultCountry(success: Bool, country: CountryElement?) {

    if success{
        // updated already
    }else {

    // Fail to get default code in these cases:
    // 1.Airplane mode.
    // 2.No SIM card in the device.
    // 3.Device is outside of cellular service range.

    // Set Default Text
    let country = CountryElement(isoCode: "USA", isoShortCode: "US", nameAr: "الولايات المتحدة الامريكية", nameEn: "United States", countryInternationlKey: "+1",phoneRegex:"")
    countryTextField.updateCountryDisplay(country: country)

    }

}

想帮忙?

修复了一个错误,或者添加了一个新功能?创建一个pull request去看看吧!